|
4 | 4 | * @author Neil Manvar
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +// import Sauce TestNG helper libraries |
7 | 8 | import com.saucelabs.common.SauceOnDemandAuthentication;
|
8 | 9 | import com.saucelabs.common.SauceOnDemandSessionIdProvider;
|
9 | 10 | import com.saucelabs.testng.SauceOnDemandAuthenticationProvider;
|
10 | 11 | import com.saucelabs.testng.SauceOnDemandTestListener;
|
11 | 12 |
|
12 |
| -import org.openqa.selenium.By; |
13 |
| -import org.openqa.selenium.Keys; |
| 13 | +// import selenium libraries |
14 | 14 | import org.openqa.selenium.WebDriver;
|
15 |
| -import org.openqa.selenium.WebElement; |
16 | 15 | import org.openqa.selenium.remote.DesiredCapabilities;
|
17 | 16 | import org.openqa.selenium.remote.CapabilityType;
|
18 | 17 | 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 |
22 | 20 | import org.testng.annotations.AfterMethod;
|
23 |
| -import org.testng.annotations.BeforeMethod; |
24 | 21 | import org.testng.annotations.DataProvider;
|
25 | 22 | import org.testng.annotations.Listeners;
|
26 | 23 | import org.testng.annotations.Test;
|
| 24 | +import static org.testng.Assert.*; |
27 | 25 |
|
28 | 26 | import java.lang.reflect.Method;
|
29 | 27 | import java.net.MalformedURLException;
|
30 | 28 | import java.net.URL;
|
31 | 29 |
|
32 |
| -import static org.testng.Assert.assertEquals; |
| 30 | +// import page objects |
| 31 | +import com.yourcompany.Pages.*; |
33 | 32 |
|
34 | 33 |
|
35 | 34 | /**
|
|
40 | 39 | @Listeners({SauceOnDemandTestListener.class})
|
41 | 40 | public class SampleSauceTest implements SauceOnDemandSessionIdProvider, SauceOnDemandAuthenticationProvider {
|
42 | 41 |
|
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"); |
45 | 44 |
|
46 | 45 | /**
|
47 | 46 | * 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) {
|
75 | 74 | new Object[]{"firefox", "35", "Windows 7"}
|
76 | 75 | };
|
77 | 76 | }
|
| 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 | + } |
78 | 85 |
|
79 | 86 | /**
|
80 | 87 | * 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 {
|
125 | 132 | * @throws Exception if an error occurs during the running of the test
|
126 | 133 | */
|
127 | 134 | @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 { |
146 | 136 | 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"); |
159 | 141 | }
|
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 | + |
170 | 143 | @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 { |
172 | 145 | 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); |
187 | 154 | }
|
188 | 155 |
|
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 | + |
196 | 157 |
|
197 | 158 | /**
|
198 | 159 | *
|
|
0 commit comments