Fix/selenium config (#2007)

* 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 Page Object Pattern
Add Chromedrivers
Include hamcrest dependency for matchers on tests
Add PageObjects for Start Here and Home Page
Create config class for selenium

* Update Readme file
Add About page and model for additional example
Create new test for new impl

* Change if to switch statement
Add Matcher and pattern to match os name

* Update imports

* remove merge conflict notation
This commit is contained in:
Walter Gómez 2017-06-10 09:19:38 -06:00 committed by Grzegorz Piwowarek
parent 4591eecddb
commit 5453e6753a
2 changed files with 66 additions and 8 deletions

View File

@ -7,6 +7,8 @@ import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SeleniumConfig {
@ -18,14 +20,20 @@ public class SeleniumConfig {
}
static {
if (getOsName("os.name").toLowerCase().contains("mac")) {
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"));
} else if (getOsName("os.name").toLowerCase().contains("nix") ||
getOsName("os.name").toLowerCase().contains("nux") ||
getOsName("os.name").toLowerCase().contains("aix")) {
break;
case "nux":
System.setProperty("webdriver.chrome.driver", findFile("chromedriver.linux"));
} else if (getOsName("os.name").toLowerCase().contains("win")) {
break;
case "win":
System.setProperty("webdriver.chrome.driver", findFile("chromedriver.exe"));
break;
}
}
}

View File

@ -0,0 +1,50 @@
package test.java.com.baeldung.selenium.junit;
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 org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class SeleniumPageObjectTest {
private SeleniumConfig config;
private BaeldungHomePage homePage;
private BaeldungAbout about;
@Before
public void setUp() {
config = new SeleniumConfig();
homePage = new BaeldungHomePage(config);
about = new BaeldungAbout(config);
}
@After
public void teardown() {
config.close();
}
@Test
public void givenHomePage_whenNavigate_thenTitleMatch() {
homePage.navigate();
assertThat(homePage.getPageTitle(), is("Baeldung"));
}
@Test
public void givenHomePage_whenNavigate_thenShouldBeInStartHere() {
homePage.navigate();
StartHerePage startHerePage = homePage.clickOnStartHere();
assertThat(startHerePage.getPageTitle(), is("Start Here"));
}
@Test
public void givenAboutPage_whenNavigate_thenTitleMatch() {
about.navigateTo();
assertThat(about.getPageTitle(), is("About Baeldung"));
}
}