diff --git a/pom.xml b/pom.xml index 5332103..5280f60 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,6 @@ common junit - quickstart-archetype diff --git a/quickstart-archetype/pom.xml b/quickstart-archetype/pom.xml deleted file mode 100644 index 6efe4c7..0000000 --- a/quickstart-archetype/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - 4.0.0 - - sauce_java - com.saucelabs - 2.1.26-SNAPSHOT - - quickstart-archetype - quickstart-archetype - pom - - quickstart-webdriver-junit - quickstart-webdriver-testng - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - Sauce Labs - http://www.saucelabs.com/ - - - - Sauce Labs - http://www.saucelabs.com/ - - - - - - com.saucelabs - saucerest - 1.0.32 - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - test - - - - - - maven-compiler-plugin - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - $project.artifactId} - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.6 - 1.6 - - - - - - diff --git a/quickstart-archetype/quickstart-webdriver-junit/pom.xml b/quickstart-archetype/quickstart-webdriver-junit/pom.xml deleted file mode 100644 index ac9289a..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - 4.0.0 - - quickstart-archetype - com.saucelabs - 2.1.26-SNAPSHOT - - quickstart-webdriver-junit - quickstart-webdriver-junit - jar - - - - src/main/resources - true - - META-INF/maven/archetype-metadata.xml - - - - src/main/resources - false - - META-INF/maven/archetype-metadata.xml - - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-junit/quickstart-junit.iml b/quickstart-archetype/quickstart-webdriver-junit/quickstart-junit.iml deleted file mode 100644 index a34cb48..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/quickstart-junit.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/META-INF/maven/archetype-metadata.xml b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index 88c9055..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - src/test/java - - **/*.java - - - - - - - - ${project.version} - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/README.md b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/README.md deleted file mode 100644 index c0488ea..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/README.md +++ /dev/null @@ -1,9 +0,0 @@ -This project contains sample source code that demonstrates how to construct a JUnit test to run a -WebDriver instance against Sauce OnDemand. - -It contains one classes, SampleSauceTest.java, which demonstrates how to configure how to run tests in parallel against -multiple browsers and integrate the Sauce JUnit Helper classes. - -The tests can be run by executing - - mvn test \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/pom.xml b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index c68b86f..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - $project.artifactId} - ${groupId} - ${version} - jar - sauce_quickstart - A sample Maven project that demonstrates how to integrate Sauce OnDemand with WebDriver tests - that run using JUnit - - - - - junit - junit - 4.11 - test - - - org.seleniumhq.selenium - selenium-java - 2.52.0 - test - - - com.saucelabs - sauce_junit - ${projectVersion} - test - - - - - - - - maven-compiler-plugin - 3.0 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19 - - true - - - - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java deleted file mode 100644 index f2b5c50..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java +++ /dev/null @@ -1,165 +0,0 @@ -package ${groupId}; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import com.saucelabs.junit.Parallelized; -import com.saucelabs.junit.ConcurrentParameterized; -import com.saucelabs.junit.SauceOnDemandTestWatcher; - -import java.net.URL; -import java.util.LinkedList; - -import static org.junit.Assert.assertEquals; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import com.saucelabs.common.SauceOnDemandSessionIdProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -import java.net.URL; -import java.util.LinkedList; - -import static org.junit.Assert.assertEquals; - -/** - * Demonstrates how to write a JUnit test that runs tests against Sauce Labs using multiple browsers in parallel. - *

- * The test also includes the {@link SauceOnDemandTestWatcher} which will invoke the Sauce REST API to mark - * the test as passed or failed. - * - * @author Ross Rowe - */ -@RunWith(ConcurrentParameterized.class) -public class SampleSauceTest implements SauceOnDemandSessionIdProvider { - - /** - * Constructs a {@link SauceOnDemandAuthentication} instance using the supplied user name/access key. To use the authentication - * supplied by environment variables or from an external file, use the no-arg {@link SauceOnDemandAuthentication} constructor. - */ - public SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication("${userName}", "${accessKey}"); - - /** - * JUnit Rule which will mark the Sauce Job as passed/failed when the test succeeds or fails. - */ - @Rule - public SauceOnDemandTestWatcher resultReportingTestWatcher = new SauceOnDemandTestWatcher(this, authentication); - - /** - * Represents the browser to be used as part of the test run. - */ - private String browser; - /** - * Represents the operating system to be used as part of the test run. - */ - private String os; - /** - * Represents the version of the browser to be used as part of the test run. - */ - private String version; - /** - * Instance variable which contains the Sauce Job Id. - */ - private String sessionId; - - /** - * The {@link WebDriver} instance which is used to perform browser interactions with. - */ - private WebDriver driver; - - /** - * Constructs a new instance of the test. The constructor requires three string parameters, which represent the operating - * system, version and browser to be used when launching a Sauce VM. The order of the parameters should be the same - * as that of the elements within the {@link #browsersStrings()} method. - * @param os - * @param version - * @param browser - */ - public SampleSauceTest(String os, String version, String browser) { - super(); - this.os = os; - this.version = version; - this.browser = browser; - } - - /** - * @return a LinkedList containing String arrays representing the browser combinations the test should be run against. The values - * in the String array are used as part of the invocation of the test constructor - */ - @ConcurrentParameterized.Parameters - public static LinkedList browsersStrings() { - LinkedList browsers = new LinkedList(); - browsers.add(new String[]{"Windows 8.1", "11", "internet explorer"}); - browsers.add(new String[]{"OSX 10.8", "6", "safari"}); - return browsers; - } - - - /** - * Constructs a new {@link RemoteWebDriver} instance which is configured to use the capabilities defined by the {@link #browser}, - * {@link #version} and {@link #os} instance variables, and which is configured to run against ondemand.saucelabs.com, using - * the username and access key populated by the {@link #authentication} instance. - * - * @throws Exception if an error occurs during the creation of the {@link RemoteWebDriver} instance. - */ - @Before - public void setUp() throws Exception { - - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(CapabilityType.BROWSER_NAME, browser); - if (version != null) { - capabilities.setCapability(CapabilityType.VERSION, version); - } - capabilities.setCapability(CapabilityType.PLATFORM, os); - capabilities.setCapability("name", "Sauce Sample Test"); - this.driver = new RemoteWebDriver( - new URL("https://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:443/wd/hub"), - capabilities); - this.sessionId = (((RemoteWebDriver) driver).getSessionId()).toString(); - - } - - /** - * Runs a simple test verifying the title of the sauce labs test page. - * @throws Exception - */ - @Test - public void sauceGuineaPig() throws Exception { - driver.get("https://saucelabs.com/test/guinea-pig"); - assertEquals("I am a page title - Sauce Labs", driver.getTitle()); - } - - /** - * Closes the {@link WebDriver} session. - * - * @throws Exception - */ - @After - public void tearDown() throws Exception { - driver.quit(); - } - - /** - * - * @return the value of the Sauce Job id. - */ - @Override - public String getSessionId() { - return sessionId; - } -} diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java deleted file mode 100644 index 090a0e6..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java +++ /dev/null @@ -1,159 +0,0 @@ -package ${groupId}; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * @author Ross Rowe - */ -public class WebDriverDemoShootoutTest { - - private SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication("${userName}", "${accessKey}"); - - private WebDriver driver; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = DesiredCapabilities.firefox(); - capabilities.setCapability("version", "17"); - capabilities.setCapability("platform", Platform.XP); - this.driver = new RemoteWebDriver( - new URL("https://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:443/wd/hub"), - capabilities); - driver.get("http://tutorialapp.saucelabs.com"); - } - - @After - public void tearDown() throws Exception { - driver.quit(); - } - - @Test - public void testLoginFailsWithBadCredentials() throws Exception { - String userName = getUniqueId(); - String password = getUniqueId(); - driver.findElement(By.name("login")).sendKeys(userName); - driver.findElement(By.name("password")).sendKeys(password); - driver.findElement(By.cssSelector("input.login")).click(); - assertNotNull("Text not found", driver.findElement(By.id("message"))); - } - - @Test - public void testLogout() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, true); - } - - @Test - public void testLogin() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, true); - doLogin(userDetails.get("username"), userDetails.get("password")); - } - - @Test - public void testRegister() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, false); - assertTrue("Message not found", driver.findElement(By.cssSelector(".username")).getText().contains("You are logged in as ")); - } - - @Test - public void testRegisterFailsWithoutUsername() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("username", ""); - doRegister(userDetails, false); - assertEquals("Message not found", "Please enter a value", driver.findElement(By.cssSelector(".error")).getText()); - - } - - @Test - public void testRegisterFailsWithoutName() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("name", ""); - doRegister(userDetails, false); - assertEquals("Message not found", "Please enter a value", driver.findElement(By.cssSelector(".error")).getText()); - } - - @Test - public void testRegisterFailsWithMismatchedPasswords() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("confirm_password", getUniqueId()); - doRegister(userDetails, false); - assertEquals("Message not found", "Fields do not match", driver.findElement(By.cssSelector(".error")).getText()); - } - - @Test - public void testRegisterFailsWithBadEmail() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("email", "test"); - doRegister(userDetails, false); - assertEquals("Message not found", "An email address must contain a single @", driver.findElement(By.cssSelector(".error")).getText()); - driver.findElement(By.id("email")).clear(); - driver.findElement(By.id("email")).sendKeys("@example.com"); - driver.findElement(By.id("form.submitted")).click(); - assertEquals("Message not found", "The username portion of the email address is invalid (the portion before the @: )", driver.findElement(By.cssSelector(".error")).getText()); - driver.findElement(By.id("email")).clear(); - driver.findElement(By.id("email")).sendKeys("test@example"); - driver.findElement(By.id("form.submitted")).click(); - assertEquals("Message not found", "The domain portion of the email address is invalid (the portion after the @: example)", driver.findElement(By.cssSelector(".error")).getText()); - } - - private String getUniqueId() { - return Long.toHexString(Double.doubleToLongBits(Math.random())); - } - - private void doRegister(Map userDetails, boolean logout) { - userDetails.put("confirm_password", userDetails.get("confirm_password") != null ? - userDetails.get("confirm_password") : userDetails.get("password")); - driver.get("http://tutorialapp.saucelabs.com/register"); - driver.findElement(By.id("username")).sendKeys(userDetails.get("username")); - driver.findElement(By.id("password")).sendKeys(userDetails.get("password")); - driver.findElement(By.id("confirm_password")).sendKeys(userDetails.get("confirm_password")); - driver.findElement(By.id("name")).sendKeys(userDetails.get("name")); - driver.findElement(By.id("email")).sendKeys(userDetails.get("email")); - driver.findElement(By.id("form.submitted")).click(); - - if (logout) { - doLogout(); - } - } - - private void doLogout() { - driver.get("http://tutorialapp.saucelabs.com/logout"); - assertEquals("Message not found", "Logged out successfully.", driver.findElement(By.id("message")).getText()); - } - - private Map createRandomUser() { - Map userDetails = new HashMap(); - String fakeId = getUniqueId(); - userDetails.put("username", fakeId); - userDetails.put("password", "testpass"); - userDetails.put("name", "Fake " + fakeId); - userDetails.put("email", fakeId + "@example.com"); - return userDetails; - } - - private void doLogin(String username, String password) { - driver.findElement(By.name("login")).sendKeys(username); - driver.findElement(By.name("password")).sendKeys(password); - driver.findElement(By.cssSelector("input.login")).click(); - assertEquals("Message not found", "Logged in successfully.", driver.findElement(By.id("message")).getText()); - } - -} diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java deleted file mode 100644 index d41b719..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package ${groupId}; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import com.saucelabs.common.SauceOnDemandSessionIdProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -import java.net.URL; - -import static org.junit.Assert.assertEquals; - -/** - * Simple {@link RemoteWebDriver} test that demonstrates how to run your Selenium tests with Sauce OnDemand. - * * - * @author Ross Rowe - */ -public class WebDriverTest { - - private WebDriver driver; - - @Before - public void setUp() throws Exception { - - DesiredCapabilities capabilities = DesiredCapabilities.firefox(); - capabilities.setCapability("version", "17"); - capabilities.setCapability("platform", Platform.XP); - this.driver = new RemoteWebDriver( - new URL("http://${userName}:${accessKey}@ondemand.saucelabs.com:80/wd/hub"), - capabilities); - } - - @Test - public void webDriver() throws Exception { - driver.get("https://saucelabs.com/test/guinea-pig"); - assertEquals("I am a page title - Sauce Labs", driver.getTitle()); - } - - @After - public void tearDown() throws Exception { - driver.quit(); - } - -} diff --git a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/resources/README b/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/resources/README deleted file mode 100644 index 157acf1..0000000 --- a/quickstart-archetype/quickstart-webdriver-junit/src/main/resources/archetype-resources/src/test/resources/README +++ /dev/null @@ -1 +0,0 @@ -This folder contains resources to be used by the test code \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/pom.xml b/quickstart-archetype/quickstart-webdriver-testng/pom.xml deleted file mode 100644 index 9160a55..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - 4.0.0 - - quickstart-archetype - com.saucelabs - 2.1.26-SNAPSHOT - - quickstart-webdriver-testng - quickstart-webdriver-testng - jar - - - - src/main/resources - true - - META-INF/maven/archetype-metadata.xml - - - - src/main/resources - false - - META-INF/maven/archetype-metadata.xml - - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/quickstart-testng.iml b/quickstart-archetype/quickstart-webdriver-testng/quickstart-testng.iml deleted file mode 100644 index a34cb48..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/quickstart-testng.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/META-INF/maven/archetype-metadata.xml b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index f66e3be..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - src/test/java - - **/*.java - - - - - - - - ${project.version} - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/README.md b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/README.md deleted file mode 100644 index ccefa4f..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/README.md +++ /dev/null @@ -1,9 +0,0 @@ -This project contains sample source code that demonstrates how to construct a TestNG test to run a -WebDriver instance against Sauce OnDemand. - -It contains one classes, SampleSauceTest.java, which demonstrates how to configure how to run tests in parallel against -multiple browsers and how to integrate the Sauce TestNG Helper classes. - -The tests can be run by executing - - mvn test \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/pom.xml b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index dd2b1c5..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - 4.0.0 - $project.artifactId} - ${groupId} - ${version} - jar - sauce_quickstart - A sample Maven project that demonstrates how to integrate Sauce OnDemand with WebDriver tests - that run using TestNG - - - - - org.testng - testng - 6.1.1 - test - - - org.seleniumhq.selenium - selenium-java - 2.52.0 - test - - - commons-lang - commons-lang - 2.6 - test - - - com.saucelabs - sauce_testng - ${projectVersion} - test - - - - - - - - maven-compiler-plugin - 3.0 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19 - - true - - - - - - \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java deleted file mode 100644 index ab692a1..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/SampleSauceTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package ${groupId}; - -/** - * @author Ross Rowe - */ - -import com.saucelabs.common.SauceOnDemandAuthentication; -import com.saucelabs.common.SauceOnDemandSessionIdProvider; -import com.saucelabs.testng.SauceOnDemandAuthenticationProvider; -import com.saucelabs.testng.SauceOnDemandTestListener; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.testng.Assert.assertEquals; - - -/** - * Simple TestNG test which demonstrates being instantiated via a DataProvider in order to supply multiple browser combinations. - * - * @author Ross Rowe - */ -@Listeners({SauceOnDemandTestListener.class}) -public class SampleSauceTest implements SauceOnDemandSessionIdProvider, SauceOnDemandAuthenticationProvider { - - /** - * Constructs a {@link com.saucelabs.common.SauceOnDemandAuthentication} instance using the supplied user name/access key. To use the authentication - * supplied by environment variables or from an external file, use the no-arg {@link com.saucelabs.common.SauceOnDemandAuthentication} constructor. - */ - public SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication("${userName}", "${accessKey}"); - - /** - * ThreadLocal variable which contains the {@link WebDriver} instance which is used to perform browser interactions with. - */ - private ThreadLocal webDriver = new ThreadLocal(); - - /** - * ThreadLocal variable which contains the Sauce Job Id. - */ - private ThreadLocal sessionId = new ThreadLocal(); - - /** - * DataProvider that explicitly sets the browser combinations to be used. - * - * @param testMethod - * @return - */ - @DataProvider(name = "hardCodedBrowsers", parallel = true) - public static Object[][] sauceBrowserDataProvider(Method testMethod) { - return new Object[][]{ - new Object[]{"internet explorer", "11", "Windows 8.1"}, - new Object[]{"safari", "6", "OSX 10.8"}, - }; - } - - /** - * /** - * Constructs a new {@link RemoteWebDriver} instance which is configured to use the capabilities defined by the browser, - * version and os parameters, and which is configured to run against ondemand.saucelabs.com, using - * the username and access key populated by the {@link #authentication} instance. - * - * @param browser Represents the browser to be used as part of the test run. - * @param version Represents the version of the browser to be used as part of the test run. - * @param os Represents the operating system to be used as part of the test run. - * @return - * @throws MalformedURLException if an error occurs parsing the url - */ - private WebDriver createDriver(String browser, String version, String os) throws MalformedURLException { - - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(CapabilityType.BROWSER_NAME, browser); - if (version != null) { - capabilities.setCapability(CapabilityType.VERSION, version); - } - capabilities.setCapability(CapabilityType.PLATFORM, os); - capabilities.setCapability("name", "Sauce Sample Test"); - webDriver.set(new RemoteWebDriver( - new URL("https://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:443/wd/hub"), - capabilities)); - sessionId.set(((RemoteWebDriver) getWebDriver()).getSessionId().toString()); - return webDriver.get(); - } - - /** - * Runs a simple test verifying the title of the sauce test page. - * - * @param browser Represents the browser to be used as part of the test run. - * @param version Represents the version of the browser to be used as part of the test run. - * @param os Represents the operating system to be used as part of the test run. - * @throws Exception if an error occurs during the running of the test - */ - @Test(dataProvider = "hardCodedBrowsers") - public void webDriver(String browser, String version, String os) throws Exception { - WebDriver driver = createDriver(browser, version, os); - driver.get("https://saucelabs.com/test/guinea-pig"); - assertEquals(driver.getTitle(), "I am a page title - Sauce Labs"); - driver.quit(); - } - - /** - * @return the {@link WebDriver} for the current thread - */ - public WebDriver getWebDriver() { - System.out.println("WebDriver" + webDriver.get()); - return webDriver.get(); - } - - /** - * - * @return the Sauce Job id for the current thread - */ - public String getSessionId() { - return sessionId.get(); - } - - /** - * - * @return the {@link SauceOnDemandAuthentication} instance containing the Sauce username/access key - */ - @Override - public SauceOnDemandAuthentication getAuthentication() { - return authentication; - } -} - diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java deleted file mode 100644 index 3013d7c..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverDemoShootoutTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package ${groupId}; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import org.openqa.selenium.By; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import static org.testng.Assert.*; - -/** - * @author Ross Rowe - */ -public class WebDriverDemoShootoutTest { - - private SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication("${userName}", "${accessKey}"); - - private WebDriver driver; - - @BeforeMethod - public void setUp() throws Exception { - DesiredCapabilities capabilities = DesiredCapabilities.firefox(); - capabilities.setCapability("version", "17"); - capabilities.setCapability("platform", Platform.XP); - this.driver = new RemoteWebDriver( - new URL("https://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:443/wd/hub"), - capabilities); - driver.get("http://tutorialapp.saucelabs.com"); - } - - @AfterMethod - public void tearDown() throws Exception { - driver.quit(); - } - - @Test - public void testLogout() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, true); - } - - @Test - public void testLoginFailsWithBadCredentials() throws Exception { - String userName = getUniqueId(); - String password = getUniqueId(); - driver.findElement(By.name("login")).sendKeys(userName); - driver.findElement(By.name("password")).sendKeys(password); - driver.findElement(By.cssSelector("input.login")).click(); - assertNotNull(driver.findElement(By.id("message")), "Text not found"); - } - - @Test - public void testLogin() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, true); - doLogin(userDetails.get("username"), userDetails.get("password")); - } - - @Test - public void testRegister() throws Exception { - Map userDetails = createRandomUser(); - doRegister(userDetails, false); - assertTrue(driver.findElement(By.cssSelector(".username")).getText().contains("You are logged in as "), "Message not found"); - } - - @Test - public void testRegisterFailsWithoutUsername() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("username", ""); - doRegister(userDetails, false); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "Please enter a value", "Message not found"); - - } - - @Test - public void testRegisterFailsWithoutName() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("name", ""); - doRegister(userDetails, false); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "Please enter a value", "Message not found"); - } - - @Test - public void testRegisterFailsWithMismatchedPasswords() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("confirm_password", getUniqueId()); - doRegister(userDetails, false); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "Fields do not match", "Message not found"); - } - - @Test - public void testRegisterFailsWithBadEmail() throws Exception { - Map userDetails = createRandomUser(); - userDetails.put("email", "test"); - doRegister(userDetails, false); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "An email address must contain a single @", "Message not found"); - driver.findElement(By.id("email")).clear(); - driver.findElement(By.id("email")).sendKeys("@example.com"); - driver.findElement(By.id("form.submitted")).click(); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "The username portion of the email address is invalid (the portion before the @: )", "Message not found"); - driver.findElement(By.id("email")).clear(); - driver.findElement(By.id("email")).sendKeys("test@example"); - driver.findElement(By.id("form.submitted")).click(); - assertEquals(driver.findElement(By.cssSelector(".error")).getText(), "The domain portion of the email address is invalid (the portion after the @: example)", "Message not found"); - } - - private String getUniqueId() { - return Long.toHexString(Double.doubleToLongBits(Math.random())); - } - - private void doRegister(Map userDetails, boolean logout) { - userDetails.put("confirm_password", userDetails.get("confirm_password") != null ? - userDetails.get("confirm_password") : userDetails.get("password")); - driver.get("http://tutorialapp.saucelabs.com/register"); - driver.findElement(By.id("username")).sendKeys(userDetails.get("username")); - driver.findElement(By.id("password")).sendKeys(userDetails.get("password")); - driver.findElement(By.id("confirm_password")).sendKeys(userDetails.get("confirm_password")); - driver.findElement(By.id("name")).sendKeys(userDetails.get("name")); - driver.findElement(By.id("email")).sendKeys(userDetails.get("email")); - driver.findElement(By.id("form.submitted")).click(); - - if (logout) { - doLogout(); - } - } - - private void doLogout() { - driver.get("http://tutorialapp.saucelabs.com/logout"); - assertEquals(driver.findElement(By.id("message")).getText(), "Logged out successfully.", "Message not found"); - } - - private Map createRandomUser() { - Map userDetails = new HashMap(); - String fakeId = getUniqueId(); - userDetails.put("username", fakeId); - userDetails.put("password", "testpass"); - userDetails.put("name", "Fake " + fakeId); - userDetails.put("email", fakeId + "@example.com"); - return userDetails; - } - - private void doLogin(String username, String password) { - driver.findElement(By.name("login")).sendKeys(username); - driver.findElement(By.name("password")).sendKeys(password); - driver.findElement(By.cssSelector("input.login")).click(); - assertEquals(driver.findElement(By.id("message")).getText(), "Logged in successfully.", "Message not found"); - } - -} \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java deleted file mode 100644 index 957d878..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/java/WebDriverTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package ${groupId}; - -import com.saucelabs.common.SauceOnDemandAuthentication; -import com.saucelabs.common.SauceOnDemandSessionIdProvider; -import org.apache.commons.lang.StringUtils; -import org.openqa.selenium.Platform; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.testng.annotations.*; - -import java.lang.reflect.Method; -import java.net.URL; - -import static org.testng.Assert.assertEquals; - -/** - * Simple {@link RemoteWebDriver} test that demonstrates how to run your Selenium tests with Sauce OnDemand. - * - * @author Ross Rowe - */ -public class WebDriverTest { - - private WebDriver driver; - - /** - * Creates a new {@link RemoteWebDriver} instance to be used to run WebDriver tests using Sauce. - * - * @param username the Sauce username - * @param key the Sauce access key - * @param os the operating system to be used - * @param browser the name of the browser to be used - * @param browserVersion the version of the browser to be used - * @param method the test method being executed - * @throws Exception thrown if any errors occur in the creation of the WebDriver instance - */ - @Parameters({"username", "key", "os", "browser", "browserVersion"}) - @BeforeMethod - public void setUp(@Optional("${userName}") String username, - @Optional("${accessKey}") String key, - @Optional("Windows 2003") String os, - @Optional("firefox") String browser, - @Optional("17") String browserVersion, - Method method) throws Exception { - - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setBrowserName(browser); - capabilities.setCapability("version", browserVersion); - capabilities.setCapability("platform", os); - capabilities.setCapability("name", method.getName()); - this.driver = new RemoteWebDriver( - new URL("http://" + username + ":" + key + "@ondemand.saucelabs.com:80/wd/hub"), - capabilities); - } - - @Test - public void webDriver() throws Exception { - driver.get("https://saucelabs.com/test/guinea-pig"); - assertEquals(driver.getTitle(), "I am a page title - Sauce Labs"); - } - - @AfterMethod - public void tearDown() throws Exception { - driver.quit(); - } -} diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/README b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/README deleted file mode 100644 index 157acf1..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/README +++ /dev/null @@ -1 +0,0 @@ -This folder contains resources to be used by the test code \ No newline at end of file diff --git a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/testng.xml b/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/testng.xml deleted file mode 100644 index 9ce750b..0000000 --- a/quickstart-archetype/quickstart-webdriver-testng/src/main/resources/archetype-resources/src/test/resources/testng.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - -