-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove sauce bindings from selenium examples
- Loading branch information
1 parent
b87ffb4
commit 45ed2be
Showing
30 changed files
with
376 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,18 @@ | ||
# Selenium examples | ||
This folder contains Selenium examples | ||
|
||
## Examples | ||
This is the default project for all Selenium and Sauce Labs features | ||
|
||
- [Accessibility Test with Sauce Bindings](../selenium-examples/src/test/java/com/saucedemo/accessibility/SauceBindingsExampleTest.java) | ||
- [Accessibility Test with Deque Axe](../selenium-examples/src/test/java/com/saucedemo/accessibility/DequeAxeExampleTest.java) | ||
- [Simple web test, Junit 5](../selenium-examples/src/test/java/com/saucedemo/JUnit5W3CChromeTest.java) | ||
- [Simple Headless test, TestNG](../selenium-examples/src/test/java/com/saucedemo/SampleHeadlessSauceTest.java) | ||
- [Sauce Status Updates w/ JUnit 3](../selenium-examples/src/test/java/com/saucedemo/JUnit3UpdateSauceStatusTest.java) | ||
* Demo package for seeing Sauce Demo site tests | ||
* Sauce Features package for demos of executing special Sauce Labs features | ||
* Selenium Features package for demos of executing Selenium on Sauce Labs | ||
|
||
## How to run tests | ||
It is also to demonstrate how to run tests in parallel with Selenium 4 and JUnit 5. See [pom.xml](pom.xml) | ||
|
||
### JUnit 5 test | ||
## Execute tests in parallel: | ||
```bash | ||
cd selenium-examples | ||
mvn test -Dtest=JUnit5W3CChromeTest | ||
mvn test -Dsurefire.parallel=20 | ||
``` | ||
|
||
Your output will look like this if done correctly | ||
|
||
```java | ||
[INFO] Scanning for projects... | ||
[INFO] | ||
[INFO] ------------------< com.saucelabs:selenium-examples >------------------- | ||
[INFO] Building selenium-examples 1.0-SNAPSHOT | ||
[INFO] --------------------------------[ jar ]--------------------------------- | ||
[INFO] | ||
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ selenium-examples --- | ||
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! | ||
[INFO] Copying 0 resource | ||
[INFO] | ||
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ selenium-examples --- | ||
[INFO] Nothing to compile - all classes are up to date | ||
[INFO] | ||
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ selenium-examples --- | ||
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! | ||
[INFO] skip non existing resourceDirectory /Users/nikolayadvolodkin/Documents/source/java/demo-java/selenium-examples/src/test/resources | ||
[INFO] | ||
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ selenium-examples --- | ||
[INFO] Nothing to compile - all classes are up to date | ||
[INFO] | ||
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ selenium-examples --- | ||
[INFO] | ||
[INFO] ------------------------------------------------------- | ||
[INFO] T E S T S | ||
[INFO] ------------------------------------------------------- | ||
[INFO] Running com.saucedemo.JUnit5W3CChromeTest | ||
Apr 05, 2021 1:48:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession | ||
INFO: Detected dialect: W3C | ||
SauceOnDemandSessionID=c36e76bd99964b29824e3c9597558659 job-name=Junit5W3CChromeTest | ||
Test Job Link: https://app.saucelabs.com/tests/c36e76bd99964b29824e3c9597558659 | ||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.44 s - in com.saucedemo.JUnit5W3CChromeTest | ||
[INFO] | ||
[INFO] Results: | ||
[INFO] | ||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 | ||
[INFO] | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] BUILD SUCCESS | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] Total time: 9.728 s | ||
[INFO] Finished at: 2021-04-05T13:48:14-04:00 | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
selenium-examples/src/test/java/com/saucedemo/selenium/SeleniumTestBase.java
This file was deleted.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
selenium-examples/src/test/java/com/saucedemo/selenium/TestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.saucedemo.selenium; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.junit.jupiter.api.extension.TestWatcher; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.MutableCapabilities; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.firefox.FirefoxOptions; | ||
import org.openqa.selenium.remote.RemoteWebDriver; | ||
import org.openqa.selenium.remote.SessionId; | ||
|
||
public class TestBase { | ||
|
||
public WebDriver driver; | ||
|
||
@RegisterExtension public TestBase.SauceTestWatcher watcher = new TestBase.SauceTestWatcher(); | ||
protected TestInfo testInfo; | ||
protected SessionId id; | ||
|
||
public void startChromeSession(TestInfo testInfo) { | ||
ChromeOptions options = new ChromeOptions(); | ||
// options.setPlatformName("Windows 10"); | ||
// options.setBrowserVersion("latest"); | ||
|
||
startSession(testInfo, options); | ||
} | ||
|
||
public void startEdgeSession(TestInfo testInfo) { | ||
ChromeOptions options = new ChromeOptions(); | ||
// options.setPlatformName("Windows 10"); | ||
// options.setBrowserVersion("latest"); | ||
|
||
startSession(testInfo, options); | ||
} | ||
|
||
public void startFirefoxSession(TestInfo testInfo) { | ||
FirefoxOptions options = new FirefoxOptions(); | ||
// options.setPlatformName("Windows 10"); | ||
// options.setBrowserVersion("latest"); | ||
|
||
startSession(testInfo, options); | ||
} | ||
|
||
public void startSession(TestInfo testInfo, Capabilities options) { | ||
startSession(testInfo, options, new HashMap<>()); | ||
} | ||
|
||
protected void startSession(TestInfo testInfo, Capabilities options, Map<String, Object> sauceOptions) { | ||
Objects.requireNonNull(testInfo, "testInfo cannot be null"); | ||
Objects.requireNonNull(options, "options cannot be null"); | ||
Objects.requireNonNull(sauceOptions, "sauceOptions cannot be null"); | ||
|
||
this.testInfo = testInfo; | ||
|
||
sauceOptions.put("username", System.getenv("SAUCE_USERNAME")); | ||
sauceOptions.put("accessKey", System.getenv("SAUCE_ACCESS_KEY")); | ||
sauceOptions.put("name", testInfo.getDisplayName()); | ||
((MutableCapabilities) options).setCapability("sauce:options", sauceOptions); | ||
|
||
URL url; | ||
try { | ||
url = new URL("https://ondemand.us-west-1.saucelabs.com/wd/hub"); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
driver = new RemoteWebDriver(url, options); | ||
this.id = ((RemoteWebDriver) driver).getSessionId(); | ||
} | ||
|
||
public class SauceTestWatcher implements TestWatcher { | ||
@Override | ||
public void testSuccessful(ExtensionContext context) { | ||
printResults(); | ||
try { | ||
((JavascriptExecutor) driver).executeScript("sauce:job-result=passed"); | ||
driver.quit(); | ||
} catch (Exception e) { | ||
System.out.println("problem with using driver: " + e); | ||
} | ||
} | ||
|
||
@Override | ||
public void testFailed(ExtensionContext context, Throwable cause) { | ||
printResults(); | ||
|
||
try { | ||
((JavascriptExecutor) driver).executeScript("sauce:job-result=failed"); | ||
driver.quit(); | ||
} catch (Exception e) { | ||
System.out.println("problem with using driver: " + e); | ||
} | ||
} | ||
|
||
public void printResults() { | ||
String sauceReporter = | ||
String.format("SauceOnDemandSessionID=%s job-name=%s", id, testInfo.getDisplayName()); | ||
String sauceTestLink = String.format("Test Job Link: https://app.saucelabs.com/tests/%s", id); | ||
System.out.print(sauceReporter + "\n" + sauceTestLink + "\n"); | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
selenium-examples/src/test/java/com/saucedemo/selenium/accessibility/SauceBindingsTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.