Skip to content

Commit 476b008

Browse files
NeilNeil
Neil
authored and
Neil
committed
using page object and test guineapig page
1 parent ecedb69 commit 476b008

File tree

2 files changed

+56
-72
lines changed

2 files changed

+56
-72
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.yourcompany.Pages;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
public class GuineaPig {
7+
private final WebDriver driver;
8+
9+
By emailInputFieldLocator = By.id("fbemail");
10+
11+
public GuineaPig(WebDriver driver) {
12+
this.driver = driver;
13+
}
14+
15+
public void fillOutEmailInput(String inputText) {
16+
driver.findElement(emailInputFieldLocator).sendKeys(inputText);
17+
}
18+
19+
public String getEmailInput() {
20+
return driver.findElement(emailInputFieldLocator).getAttribute("value");
21+
}
22+
23+
}

src/test/java/com/yourcompany/SampleSauceTest.java

Lines changed: 33 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@
44
* @author Neil Manvar
55
*/
66

7+
// import Sauce TestNG helper libraries
78
import com.saucelabs.common.SauceOnDemandAuthentication;
89
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
910
import com.saucelabs.testng.SauceOnDemandAuthenticationProvider;
1011
import com.saucelabs.testng.SauceOnDemandTestListener;
1112

12-
import org.openqa.selenium.By;
13-
import org.openqa.selenium.Keys;
13+
// import selenium libraries
1414
import org.openqa.selenium.WebDriver;
15-
import org.openqa.selenium.WebElement;
1615
import org.openqa.selenium.remote.DesiredCapabilities;
1716
import org.openqa.selenium.remote.CapabilityType;
1817
import org.openqa.selenium.remote.RemoteWebDriver;
19-
import org.openqa.selenium.support.ui.ExpectedConditions;
20-
import org.openqa.selenium.support.ui.WebDriverWait;
21-
import org.testng.Assert;
18+
19+
// import testng libraries
2220
import org.testng.annotations.AfterMethod;
23-
import org.testng.annotations.BeforeMethod;
2421
import org.testng.annotations.DataProvider;
2522
import org.testng.annotations.Listeners;
2623
import org.testng.annotations.Test;
24+
import static org.testng.Assert.*;
2725

2826
import java.lang.reflect.Method;
2927
import java.net.MalformedURLException;
3028
import java.net.URL;
3129

32-
import static org.testng.Assert.assertEquals;
30+
// import page objects
31+
import com.yourcompany.Pages.*;
3332

3433

3534
/**
@@ -40,8 +39,8 @@
4039
@Listeners({SauceOnDemandTestListener.class})
4140
public class SampleSauceTest implements SauceOnDemandSessionIdProvider, SauceOnDemandAuthenticationProvider {
4241

43-
public String username = System.getenv("SAUCE_USER_NAME") != null ? System.getenv("SAUCE_USER_NAME") : System.getenv("SAUCE_USERNAME");
44-
public String accesskey = System.getenv("SAUCE_API_KEY") != null ? System.getenv("SAUCE_API_KEY") : System.getenv("SAUCE_ACCESS_KEY");
42+
public String username = System.getenv("SAUCE_USERNAME");
43+
public String accesskey = System.getenv("SAUCE_ACCESS_KEY");
4544

4645
/**
4746
* Constructs a {@link SauceOnDemandAuthentication} instance using the supplied user name/access key. To use the authentication
@@ -75,6 +74,14 @@ public static Object[][] sauceBrowserDataProvider(Method testMethod) {
7574
new Object[]{"firefox", "35", "Windows 7"}
7675
};
7776
}
77+
78+
/**
79+
* @return the {@link WebDriver} for the current thread
80+
*/
81+
public WebDriver getWebDriver() {
82+
System.out.println("WebDriver" + webDriver.get());
83+
return webDriver.get();
84+
}
7885

7986
/**
8087
* Constructs a new {@link RemoteWebDriver} instance which is configured to use the capabilities defined by the browser,
@@ -125,74 +132,28 @@ public void tearDown() throws Exception {
125132
* @throws Exception if an error occurs during the running of the test
126133
*/
127134
@Test(dataProvider = "hardCodedBrowsers")
128-
public void pandoraTitleTest(String browser, String version, String os, Method method) throws Exception {
129-
WebDriver driver = createDriver(browser, version, os, method.getName());
130-
driver.get("http://www.pandora.com/");
131-
132-
assertEquals(driver.getTitle(), "Pandora Internet Radio - Listen to Free Music You'll Love");
133-
}
134-
135-
/**
136-
* Runs a simple test verifying the login form and login button of the pandora.com home page.
137-
*
138-
* @param browser Represents the browser to be used as part of the test run.
139-
* @param version Represents the version of the browser to be used as part of the test run.
140-
* @param os Represents the operating system to be used as part of the test run.
141-
* @param Method Represents the method, used for getting the name of the test/method
142-
* @throws Exception if an error occurs during the running of the test
143-
*/
144-
@Test(dataProvider = "hardCodedBrowsers")
145-
public void welcomeScreenLaunchTest(String browser, String version, String os, Method method) throws Exception {
135+
public void verifyTitleTest(String browser, String version, String os, Method method) throws Exception {
146136
WebDriver driver = createDriver(browser, version, os, method.getName());
147-
driver.get("http://www.pandora.com/");
148-
149-
WebDriverWait wait = new WebDriverWait(driver, 10);
150-
151-
// click signin button
152-
WebElement signInButton = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".message.signin a")));
153-
Thread.sleep(5000);
154-
signInButton.click();
155-
156-
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".loginForm [name=email]")));
157-
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".loginForm [name=password]")));
158-
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".message.register a")));
137+
138+
driver.get("https://saucelabs.com/test/guinea-pig");
139+
140+
assertEquals(driver.getTitle(), "I am a page title - Sauce Labs");
159141
}
160-
161-
/**
162-
* Types in coldplay in the pandora search box, clicks Coldplay, and verifies Coldplay playlist is playing
163-
*
164-
* @param browser Represents the browser to be used as part of the test run.
165-
* @param version Represents the version of the browser to be used as part of the test run.
166-
* @param os Represents the operating system to be used as part of the test run.
167-
* @param Method Represents the method, used for getting the name of the test/method
168-
* @throws Exception if an error occurs during the running of the test
169-
*/
142+
170143
@Test(dataProvider = "hardCodedBrowsers")
171-
public void coldplayTest(String browser, String version, String os, Method method) throws Exception {
144+
public void verifyEmailInputTest(String browser, String version, String os, Method method) throws Exception {
172145
WebDriver driver = createDriver(browser, version, os, method.getName());
173-
driver.get("http://www.pandora.com/");
174-
175-
WebDriverWait wait = new WebDriverWait(driver, 10);
176-
177-
// click signin button
178-
WebElement searchBox = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#welcomeSearch .searchInput")));
179-
Thread.sleep(3000);
180-
searchBox.sendKeys("coldplay");
181-
182-
WebElement coldplaySuggestion = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='searchPopupWelcomePosition']//span[contains(text(), 'Coldplay')]")));
183-
coldplaySuggestion.click();
184-
185-
WebElement topMenu = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".stationChangeSelectorNoMenu")));
186-
Assert.assertTrue(topMenu.getText().contains("Coldplay"), "Text not found!");
146+
String emailInputText = "[email protected]";
147+
148+
driver.get("https://saucelabs.com/test/guinea-pig");
149+
150+
GuineaPig page = new GuineaPig(driver);
151+
page.fillOutEmailInput(emailInputText);
152+
153+
assertEquals(page.getEmailInput(), emailInputText);
187154
}
188155

189-
/**
190-
* @return the {@link WebDriver} for the current thread
191-
*/
192-
public WebDriver getWebDriver() {
193-
System.out.println("WebDriver" + webDriver.get());
194-
return webDriver.get();
195-
}
156+
196157

197158
/**
198159
*

0 commit comments

Comments
 (0)