Skip to content

Commit

Permalink
Update test to click on the google cookies popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Estefania committed Sep 22, 2020
1 parent 39f0106 commit f23b34b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 3 additions & 9 deletions template/src/main/java/selenium/template/TestSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.apache.logging.log4j.Level;

public class TestSetup {
/** Logger class initialization. */
Expand Down Expand Up @@ -80,10 +76,8 @@ else if ("CHROME".equalsIgnoreCase(browser)) {
else{
System.setProperty("webdriver.chrome.driver", resourceFolder+os+"/chromedriver");
}

ChromeOptions option = new ChromeOptions();
option.addArguments("user-data-dir=C:\\Users\\isabe\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1");
driver = new ChromeDriver(option);

driver = new ChromeDriver();

}

Expand Down
12 changes: 12 additions & 0 deletions template/src/test/java/selenium/template/MyFirstTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package selenium.template;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

public class MyFirstTest extends TestSetup{


@Test
public void testNavigateToGoogle() {
Expand All @@ -17,6 +19,16 @@ public void testNavigateToGoogle() {
@Test
public void testNavigateAndSearchOnGoogle() {
driver.navigate().to("http://www.google.es");

// Nos cambiamos al iframe de las cookies para poder interaccionar con él.
driver.switchTo().frame(0);

JavascriptExecutor js = (JavascriptExecutor) driver;

// Forzaos el click on JavaScript
js.executeScript("window.document.getElementById('introAgreeButton').click();");


WebElement inputGoogle = driver.findElement(By.name("q"));

inputGoogle.click();
Expand Down

0 comments on commit f23b34b

Please sign in to comment.