Added chrome driver for tests.

This commit is contained in:
Andrew Pitt 2020-01-06 15:19:22 -05:00
parent 0a9e18d25b
commit d197a8e658
2 changed files with 33 additions and 12 deletions

View file

@ -19,17 +19,27 @@ public class MainPageIT {
} }
public String getTitle() { public String getTitle() {
return this.config.getDriver().getTitle(); return this.config.getFirefoxDriver().getTitle();
} }
@After @After
public void closeConnection() { public void closeConnection() {
config.getDriver().quit(); config.getFirefoxDriver().quit();
} }
@Test @Test
public void petclinicTitleIT() { public void petclinicTitleFireFoxIT() {
WebDriver driver = config.getDriver(); WebDriver driver = config.getFirefoxDriver();
driver.get(url);
assertEquals("Title not as expected: ", "PetClinic :: a Spring Framework demonstration", getTitle());
String welcomeText = driver.findElement(By.id("welcome")).getText();
assertEquals("Wrong welcome text.", "Welcome to the Red Hat Pet Clinic", welcomeText);
System.err.println("Text extracted: " + welcomeText);
}
@Test
public void petclinicTitleChromeIT() {
WebDriver driver = config.getChromeDriver();
driver.get(url); driver.get(url);
assertEquals("Title not as expected: ", "PetClinic :: a Spring Framework demonstration", getTitle()); assertEquals("Title not as expected: ", "PetClinic :: a Spring Framework demonstration", getTitle());
String welcomeText = driver.findElement(By.id("welcome")).getText(); String welcomeText = driver.findElement(By.id("welcome")).getText();

View file

@ -6,21 +6,32 @@ import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Capabilities; import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebDriver;
public class SeleniumConfig { public class SeleniumConfig {
private WebDriver driver; public static final String SELENIUM_HUB_URL = "http://selenium-hub-cicd.apps.cluster-ottawa-630b.ottawa-630b.example.opentlc.com/wd/hub";
private WebDriver firefoxDriver;
private WebDriver chromeDriver;
public SeleniumConfig() throws MalformedURLException { public SeleniumConfig() throws MalformedURLException {
Capabilities capabilities = new FirefoxOptions(); Capabilities firefoxCapabilities = new FirefoxOptions();
driver = new RemoteWebDriver( firefoxDriver = new RemoteWebDriver(new URL(SELENIUM_HUB_URL), firefoxCapabilities);
new URL("http://selenium-hub-cicd.apps.cluster-ottawa-630b.ottawa-630b.example.opentlc.com/wd/hub"), firefoxDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); Capabilities chromeCapabilities = new ChromeOptions();
chromeDriver = new RemoteWebDriver(new URL(SELENIUM_HUB_URL), chromeCapabilities);
chromeDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
} }
public WebDriver getDriver() { public WebDriver getFirefoxDriver() {
return driver; return firefoxDriver;
} }
public WebDriver getChromeDriver() {
return chromeDriver;
}
} }