Fix/update selenium config (#2095)

* Add project for hibernate immutable article
Add Event entity
Add hibernate configuration file
Add hibernateutil for configuration
Add test to match snippets from article

* Update master

* Selenium congif fix
Change chromedriver files to geckodriver
Use Firefox webdriver to stick with standard
Update tests for JUnit and TestNG
Modify SeleniumExample and move all WebDriver Configuration to corresponding class
Update selectors and copy content
This commit is contained in:
Walter Gómez 2017-06-16 01:13:36 -06:00 committed by Grzegorz Piwowarek
parent 3a04c3adc1
commit 9cf533654d
9 changed files with 25 additions and 37 deletions

Binary file not shown.

View File

@ -66,6 +66,6 @@
<properties>
<testng.version>6.10</testng.version>
<selenium-java.version>3.0.1</selenium-java.version>
<selenium-java.version>3.4.0</selenium-java.version>
</properties>
</project>

View File

@ -1,32 +1,31 @@
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;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class SeleniumExample {
private WebDriver webDriver;
private SeleniumConfig config;
private String url = "http://www.baeldung.com/";
public SeleniumExample() {
System.setProperty("webdriver.firefox.marionette", "C:\\selenium\\geckodriver.exe");
webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.get(url);
config = new SeleniumConfig();
config.getDriver().get(url);
}
public void closeWindow() {
webDriver.close();
this.config.getDriver().close();
}
public String getTitle() {
return webDriver.getTitle();
return this.config.getDriver().getTitle();
}
public void getAboutBaeldungPage() {
@ -36,7 +35,7 @@ public class SeleniumExample {
}
private void closeOverlay() {
List<WebElement> webElementList = webDriver.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")))
@ -47,14 +46,18 @@ public class SeleniumExample {
}
private void clickAboutLink() {
webDriver.findElement(By.partialLinkText("About")).click();
this.config.getDriver().findElement(By.partialLinkText("About")).click();
}
private void clickAboutUsLink() {
webDriver.findElement(By.partialLinkText("About Baeldung.")).click();
Actions builder = new Actions(config.getDriver());
WebElement element = this.config.getDriver().findElement(By.partialLinkText("About Baeldung."));
builder.moveToElement(element).build().perform();
}
public boolean isAuthorInformationAvailable() {
return webDriver.findElement(By.xpath("//*[contains(text(), 'an engineer with a passion for teaching and building stuff on the web')]")).isDisplayed();
return this.config.getDriver()
.findElement(By.cssSelector("article > .row > div"))
.isDisplayed();
}
}

View File

@ -4,9 +4,11 @@ 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;
@ -15,30 +17,13 @@ public class SeleniumConfig {
private WebDriver driver;
public SeleniumConfig() {
Capabilities capabilities = DesiredCapabilities.chrome();
driver = new ChromeDriver(capabilities);
Capabilities capabilities = DesiredCapabilities.firefox();
driver = new FirefoxDriver(capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
static {
String osName = getOsName("os.name").toLowerCase();
final Matcher matcher = Pattern.compile("(mac|nux|win)").matcher(osName);
if (matcher.find()) {
switch (matcher.group()) {
case "mac":
System.setProperty("webdriver.chrome.driver", findFile("chromedriver.mac"));
break;
case "nux":
System.setProperty("webdriver.chrome.driver", findFile("chromedriver.linux"));
break;
case "win":
System.setProperty("webdriver.chrome.driver", findFile("chromedriver.exe"));
break;
}
}
}
private static String getOsName(String prop) {
return (System.getProperty(prop));
System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac"));
}
static private String findFile(String filename) {
@ -51,7 +36,7 @@ public class SeleniumConfig {
}
public void close() {
driver.quit();
driver.close();
}
public void navigateTo(String url) {

View File

@ -10,7 +10,7 @@ import static org.testng.Assert.*;
public class SeleniumWithJUnitLiveTest {
private static SeleniumExample seleniumExample;
private String expectedTitle = "About Baeldung | Baeldung";
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@BeforeClass
public static void setUp() {

View File

@ -10,7 +10,7 @@ import static org.testng.Assert.*;
public class SeleniumWithTestNGLiveTest {
private SeleniumExample seleniumExample;
private String expectedTitle = "About Baeldung | Baeldung";
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@BeforeSuite
public void setUp() {