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:
+30
-23
@@ -1,14 +1,12 @@
|
||||
package main.java.com.baeldung.selenium;
|
||||
|
||||
import main.java.com.baeldung.selenium.config.SeleniumConfig;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
package com.baeldung.selenium;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
|
||||
import com.baeldung.selenium.config.SeleniumConfig;
|
||||
|
||||
public class SeleniumExample {
|
||||
|
||||
@@ -17,15 +15,18 @@ public class SeleniumExample {
|
||||
|
||||
public SeleniumExample() {
|
||||
config = new SeleniumConfig();
|
||||
config.getDriver().get(url);
|
||||
config.getDriver()
|
||||
.get(url);
|
||||
}
|
||||
|
||||
public void closeWindow() {
|
||||
this.config.getDriver().close();
|
||||
this.config.getDriver()
|
||||
.close();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.config.getDriver().getTitle();
|
||||
return this.config.getDriver()
|
||||
.getTitle();
|
||||
}
|
||||
|
||||
public void getAboutBaeldungPage() {
|
||||
@@ -35,29 +36,35 @@ public class SeleniumExample {
|
||||
}
|
||||
|
||||
private void closeOverlay() {
|
||||
List<WebElement> webElementList = this.config.getDriver().findElements(By.tagName("a"));
|
||||
List<WebElement> webElementList = this.config.getDriver()
|
||||
.findElements(By.tagName("a"));
|
||||
if (webElementList != null) {
|
||||
webElementList.stream()
|
||||
.filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
|
||||
.filter(WebElement::isDisplayed)
|
||||
.findAny()
|
||||
.ifPresent(WebElement::click);
|
||||
.filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
|
||||
.filter(WebElement::isDisplayed)
|
||||
.findAny()
|
||||
.ifPresent(WebElement::click);
|
||||
}
|
||||
}
|
||||
|
||||
private void clickAboutLink() {
|
||||
this.config.getDriver().findElement(By.partialLinkText("About")).click();
|
||||
Actions actions = new Actions(config.getDriver());
|
||||
WebElement aboutElement = this.config.getDriver()
|
||||
.findElement(By.id("menu-item-6138"));
|
||||
|
||||
actions.moveToElement(aboutElement).perform();
|
||||
}
|
||||
|
||||
private void clickAboutUsLink() {
|
||||
Actions builder = new Actions(config.getDriver());
|
||||
WebElement element = this.config.getDriver().findElement(By.partialLinkText("About Baeldung."));
|
||||
builder.moveToElement(element).build().perform();
|
||||
WebElement element = this.config.getDriver()
|
||||
.findElement(By.partialLinkText("About Baeldung."));
|
||||
element.click();
|
||||
}
|
||||
|
||||
public boolean isAuthorInformationAvailable() {
|
||||
return this.config.getDriver()
|
||||
.findElement(By.cssSelector("article > .row > div"))
|
||||
.isDisplayed();
|
||||
.getPageSource()
|
||||
.contains("Hey ! I'm Eugen");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,17 +1,14 @@
|
||||
package main.java.com.baeldung.selenium.config;
|
||||
package com.baeldung.selenium.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openqa.selenium.Capabilities;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SeleniumConfig {
|
||||
|
||||
private WebDriver driver;
|
||||
@@ -19,15 +16,17 @@ public class SeleniumConfig {
|
||||
public SeleniumConfig() {
|
||||
Capabilities capabilities = DesiredCapabilities.firefox();
|
||||
driver = new FirefoxDriver(capabilities);
|
||||
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
|
||||
driver.manage()
|
||||
.timeouts()
|
||||
.implicitlyWait(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
static {
|
||||
System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac"));
|
||||
}
|
||||
|
||||
static private String findFile(String filename) {
|
||||
String paths[] = {"", "bin/", "target/classes"}; // if you have chromedriver somewhere else on the path, then put it here.
|
||||
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;
|
||||
@@ -40,7 +39,8 @@ public class SeleniumConfig {
|
||||
}
|
||||
|
||||
public void navigateTo(String url) {
|
||||
driver.navigate().to(url);
|
||||
driver.navigate()
|
||||
.to(url);
|
||||
}
|
||||
|
||||
public void clickElement(WebElement element) {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package main.java.com.baeldung.selenium.models;
|
||||
package com.baeldung.selenium.models;
|
||||
|
||||
import main.java.com.baeldung.selenium.config.SeleniumConfig;
|
||||
import main.java.com.baeldung.selenium.pages.BaeldungAboutPage;
|
||||
import com.baeldung.selenium.config.SeleniumConfig;
|
||||
import com.baeldung.selenium.pages.BaeldungAboutPage;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
|
||||
public class BaeldungAbout {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package main.java.com.baeldung.selenium.pages;
|
||||
package com.baeldung.selenium.pages;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package main.java.com.baeldung.selenium.pages;
|
||||
package com.baeldung.selenium.pages;
|
||||
|
||||
import main.java.com.baeldung.selenium.config.SeleniumConfig;
|
||||
import com.baeldung.selenium.config.SeleniumConfig;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
@@ -8,7 +8,7 @@ import org.openqa.selenium.support.PageFactory;
|
||||
public class BaeldungHomePage {
|
||||
|
||||
private SeleniumConfig config;
|
||||
@FindBy(css=".header--menu > a")
|
||||
@FindBy(css = ".nav--logo_mobile")
|
||||
private WebElement title;
|
||||
@FindBy(css = ".menu-start-here > a")
|
||||
private WebElement startHere;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package main.java.com.baeldung.selenium.pages;
|
||||
package com.baeldung.selenium.pages;
|
||||
|
||||
import main.java.com.baeldung.selenium.config.SeleniumConfig;
|
||||
import com.baeldung.selenium.config.SeleniumConfig;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user