BAEL-4198 - Fix Selenium Testing module (#9611)

* BAEL-4198 - Fix Selenium Live Tests

* BAEL-4198

Co-authored-by: Jonathan Cook <jcook@sciops.esa.int>
This commit is contained in:
Jonathan Cook
2020-06-29 23:13:26 +02:00
committed by GitHub
parent ae9bc9eef1
commit eb75cf11fc
12 changed files with 128 additions and 103 deletions
@@ -1,4 +1,4 @@
package java.com.baeldung.selenium.clickusingjavascript;
package com.baeldung.selenium.clickusingjavascript;
import org.junit.After;
import org.junit.Before;
@@ -14,16 +14,18 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class SeleniumJavaScriptClickTest {
import java.io.File;
public class SeleniumJavaScriptClickLiveTest {
private WebDriver driver;
private WebDriverWait wait;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
System.setProperty("webdriver.chrome.driver", new File("src/main/resources/chromedriver.mac").getAbsolutePath());
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 5000);
wait = new WebDriverWait(driver, 20);
}
@After
@@ -37,19 +39,21 @@ public class SeleniumJavaScriptClickTest {
String title = driver.getTitle();
assertEquals("Baeldung | Java, Spring and Web Development tutorials", title);
wait.until(ExpectedConditions.elementToBeClickable(By.className("menu-search")));
WebElement searchButton = driver.findElement(By.className("menu-search"));
wait.until(ExpectedConditions.elementToBeClickable(By.className("nav--menu_item_anchor")));
WebElement searchButton = driver.findElement(By.className("nav--menu_item_anchor"));
clickElement(searchButton);
wait.until(ExpectedConditions.elementToBeClickable(By.id("search")));
WebElement searchInput = driver.findElement(By.id("search"));
searchInput.sendKeys("Selenium");
wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-search")));
WebElement seeSearchResultsButton = driver.findElement(By.className("btn-search"));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn-search")));
WebElement seeSearchResultsButton = driver.findElement(By.cssSelector(".btn-search"));
clickElement(seeSearchResultsButton);
int seleniumPostsCount = driver.findElements(By.className("post")).size();
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("post")));
int seleniumPostsCount = driver.findElements(By.className("post"))
.size();
assertTrue(seleniumPostsCount > 0);
}
@@ -1,4 +1,16 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.cookies;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import java.io.File;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@@ -9,12 +21,6 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class SeleniumCookiesJUnitLiveTest {
private WebDriver driver;
@@ -22,11 +28,21 @@ public class SeleniumCookiesJUnitLiveTest {
@Before
public void setUp() {
System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac"));
Capabilities capabilities = DesiredCapabilities.firefox();
driver = new FirefoxDriver(capabilities);
navUrl = "https://baeldung.com";
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
}
private static String findFile(String filename) {
String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here.
for (String path : paths) {
if (new File(path + filename).exists())
return path + filename;
}
return "";
}
@After
@@ -1,16 +1,21 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.junit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.testng.Assert.*;
import com.baeldung.selenium.SeleniumExample;
public class SeleniumWithJUnitLiveTest {
private static SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
private String expectedTitle = "About Baeldung | Baeldung";
@BeforeClass
public static void setUp() {
@@ -18,17 +23,17 @@ public class SeleniumWithJUnitLiveTest {
}
@AfterClass
public static void tearDown() {
public static void tearDown() throws IOException {
seleniumExample.closeWindow();
}
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(expectedTitle, actualTitle);
assertTrue(seleniumExample.isAuthorInformationAvailable());
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(expectedTitle, actualTitle);
assertTrue(seleniumExample.isAuthorInformationAvailable());
}
}
@@ -1,9 +1,9 @@
package test.java.com.baeldung.selenium.junit;
package com.baeldung.selenium.pages;
import main.java.com.baeldung.selenium.config.SeleniumConfig;
import main.java.com.baeldung.selenium.models.BaeldungAbout;
import main.java.com.baeldung.selenium.pages.BaeldungHomePage;
import main.java.com.baeldung.selenium.pages.StartHerePage;
import com.baeldung.selenium.config.SeleniumConfig;
import com.baeldung.selenium.models.BaeldungAbout;
import com.baeldung.selenium.pages.BaeldungHomePage;
import com.baeldung.selenium.pages.StartHerePage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -1,16 +1,19 @@
package test.java.com.baeldung.selenium.testng;
package com.baeldung.selenium.testng;
import com.baeldung.selenium.SeleniumExample;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class SeleniumWithTestNGLiveTest {
private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
private String expectedTitle = "About Baeldung | Baeldung";
@BeforeSuite
public void setUp() {