-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f176bb0
commit a54cbd7
Showing
11 changed files
with
661 additions
and
24 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,11 +1,61 @@ | ||
# Playwright Examples | ||
|
||
Did you know you can run Playwright tests on Sauce Labs, using Java? | ||
There is only one way to execute Playwright on Sauce Labs with Java. | ||
It works with any production version of Chrome or Edge. | ||
|
||
```bash | ||
$ export SAUCE_USERNAME=your_username | ||
$ export SAUCE_ACCESS_KEY=your_access_key | ||
$ mvn clean test | ||
``` | ||
[Setup Instructions](https://github.com/saucelabs-training/demo-java/blob/main/README.md#%EF%B8%8Fsetupprerequisites) | ||
and | ||
[Contribution Information](https://github.com/saucelabs-training/demo-java/blob/main/README.md#contributing) | ||
can be found on the [Main README](https://github.com/saucelabs-training/demo-java/blob/main/README.md). | ||
|
||
## Executing Examples | ||
The Android app being tested is found in the [My Demo App Android Repository](https://github.com/saucelabs/my-demo-app-android) | ||
|
||
1. After cloning this repo from instructions, change to this subdirectory: | ||
``` | ||
$ cd playwright-examples | ||
``` | ||
|
||
2. Run the following command to update any package dependencies: | ||
``` | ||
$ mvn dependency:resolve | ||
``` | ||
3. Then run the following command to compile your test code: | ||
``` | ||
$ mvn test-compile | ||
``` | ||
4. Finally, run the following test to see if you've properly configured the test environment: | ||
``` | ||
$ mvn clean test | ||
``` | ||
See passing tests on [GitHub Actions](https://github.com/saucelabs-training/demo-java/actions/workflows/playwright-examples.yml) | ||
## Configurations | ||
This code allows toggling which browser the tests will run on. | ||
### Chrome (default) | ||
Tests will execute on the latest version of Chrome: | ||
``` | ||
$ mvn clean test -Dsauce.browser=Chrome | ||
``` | ||
### Microsoft Edge | ||
Tests will execute on the latest version of Edge: | ||
``` | ||
$ mvn clean test -Dsauce.browser=MicrosoftEdge | ||
``` | ||
## Disclaimer | ||
> The code in these scripts is provided on an "AS-IS" basis without warranty of any kind, either | ||
> express or implied, including without limitation any implied warranties of condition, | ||
> uninterrupted | ||
> use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are | ||
> provided for educational and demonstration purposes only and should not be used in production. | ||
> Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by | ||
> the Technical Services team at Sauce Labs. | ||
> | ||
> Some examples in this repository, such as `appium-example`, `parallel-testing`, and `headless`, | ||
> may require a different account tier beyond free trial. Please contact | ||
> the [Sauce Labs Sales Team](https://saucelabs.com/contact) for support and information. |
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
43 changes: 43 additions & 0 deletions
43
playwright-examples/src/test/java/com/saucedemo/playwright/AuthenticationTest.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,43 @@ | ||
package com.saucedemo.playwright; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class AuthenticationTest extends TestBase { | ||
|
||
@Test | ||
public void signInUnsuccessful() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
|
||
page.fill("[data-test='username']", "locked_out_user"); | ||
page.fill("[data-test='password']", "secret_sauce"); | ||
page.click("[data-test='login-button']"); | ||
|
||
String errorText = page.textContent("[data-test='error']"); | ||
Assertions.assertTrue(errorText.contains("Sorry, this user has been locked out"), "Error Not Found"); | ||
} | ||
|
||
@Test | ||
public void signInSuccessful() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
|
||
page.fill("[data-test='username']", "standard_user"); | ||
page.fill("[data-test='password']", "secret_sauce"); | ||
page.click("[data-test='login-button']"); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/inventory.html", page.url(), "Login Not Successful"); | ||
} | ||
|
||
@Test | ||
public void logout() throws InterruptedException { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.fill("[data-test='username']", "standard_user"); | ||
page.fill("[data-test='password']", "secret_sauce"); | ||
page.click("[data-test='login-button']"); | ||
|
||
page.click("#react-burger-menu-btn"); | ||
page.click("#logout_sidebar_link"); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/", page.url(), "Logout Not Successful"); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
playwright-examples/src/test/java/com/saucedemo/playwright/CartTest.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,80 @@ | ||
package com.saucedemo.playwright; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CartTest extends TestBase { | ||
|
||
@Test | ||
public void addFromProductPage() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
|
||
page.locator("[data-test='add-to-cart-sauce-labs-bolt-t-shirt']").click(); | ||
|
||
Assertions.assertEquals( | ||
"1", | ||
page.locator(".shopping_cart_badge").textContent(), | ||
"Item not correctly added to cart"); | ||
} | ||
|
||
@Test | ||
public void removeFromProductPage() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-bolt-t-shirt']").click(); | ||
|
||
page.locator("[data-test='remove-sauce-labs-bolt-t-shirt']").click(); | ||
|
||
Assertions.assertEquals(0, | ||
page.locator(".shopping_cart_badge").count(), | ||
"Item not correctly removed from cart"); | ||
} | ||
|
||
@Test | ||
public void addFromInventoryPage() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
|
||
page.locator("[data-test='add-to-cart-sauce-labs-onesie']").click(); | ||
|
||
Assertions.assertEquals("1", page.locator(".shopping_cart_badge").textContent()); | ||
} | ||
|
||
@Test | ||
public void removeFromInventoryPage() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-bike-light']").click(); | ||
|
||
page.locator("[data-test='remove-sauce-labs-bike-light']").click(); | ||
|
||
Assertions.assertEquals(0, | ||
page.locator(".shopping_cart_badge").count(), | ||
"Shopping Cart is not empty"); | ||
} | ||
|
||
@Test | ||
public void removeFromCartPage() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-backpack']").click(); | ||
page.locator(".shopping_cart_link").click(); | ||
|
||
page.locator("[data-test='remove-sauce-labs-backpack']").click(); | ||
|
||
Assertions.assertEquals(0, | ||
page.locator(".shopping_cart_badge").count(), | ||
"Shopping Cart is not empty"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
playwright-examples/src/test/java/com/saucedemo/playwright/CheckoutTest.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,69 @@ | ||
package com.saucedemo.playwright; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CheckoutTest extends TestBase { | ||
|
||
@Test | ||
public void badInfo() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-onesie']").click(); | ||
page.locator(".shopping_cart_link").click(); | ||
page.locator("[data-test='checkout']").click(); | ||
|
||
page.locator("[data-test='continue']").click(); | ||
|
||
Assertions.assertTrue( | ||
page.locator("[data-test='firstName']").getAttribute("class").contains("error"), | ||
"Expected error not found on page"); | ||
} | ||
|
||
@Test | ||
public void goodInfo() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-onesie']").click(); | ||
page.locator(".shopping_cart_link").click(); | ||
page.locator("[data-test='checkout']").click(); | ||
|
||
page.locator("[data-test='firstName']").fill("Luke"); | ||
page.locator("[data-test='lastName']").fill("Perry"); | ||
page.locator("[data-test='postalCode']").fill("90210"); | ||
|
||
page.locator("[data-test='continue']").click(); | ||
|
||
Assertions.assertEquals( | ||
"https://www.saucedemo.com/checkout-step-two.html", | ||
page.url(), | ||
"Information Submission Unsuccessful"); | ||
} | ||
|
||
@Test | ||
public void completeCheckout() { | ||
page.navigate("https://www.saucedemo.com/"); | ||
page.locator("[data-test='username']").fill("standard_user"); | ||
page.locator("[data-test='password']").fill("secret_sauce"); | ||
page.locator("[data-test='login-button']").click(); | ||
page.locator("[data-test='add-to-cart-sauce-labs-onesie']").click(); | ||
page.locator(".shopping_cart_link").click(); | ||
page.locator("[data-test='checkout']").click(); | ||
page.locator("[data-test='firstName']").fill("Luke"); | ||
page.locator("[data-test='lastName']").fill("Perry"); | ||
page.locator("[data-test='postalCode']").fill("90210"); | ||
page.locator("[data-test='continue']").click(); | ||
|
||
page.locator("[data-test='finish']").click(); | ||
|
||
Assertions.assertEquals( | ||
"https://www.saucedemo.com/checkout-complete.html", | ||
page.url()); | ||
|
||
Assertions.assertTrue(page.locator(".complete-text").isVisible()); | ||
} | ||
} |
Oops, something went wrong.