-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java] add a practice test suite to simulate real world usage (#344)
* [java] add a practice test suite to simulate real world usage * [rename package to exampleservice
- Loading branch information
1 parent
717c4f5
commit 5f8cd01
Showing
72 changed files
with
3,766 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This workflow will build a Java project with Maven | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Integration Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'java/**' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- 'java/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: axel-op/googlejavaformat-action@v3 | ||
with: | ||
args: "--replace" | ||
files: "java/test-project/**/*.java" | ||
skip-commit: true | ||
- name: Print diffs | ||
run: git --no-pager diff --exit-code | ||
integration: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
profile: [junit4, junit5, testng] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 11 | ||
distribution: 'temurin' | ||
- name: Remove driver directories | ||
run: | | ||
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER | ||
- name: Install main bindings snapshot | ||
run: cd java/main && mvn clean package install -DskipTests -Dgpg.skip=true | ||
- name: Install Junit5 bindings snapshot | ||
run: cd java/junit5 && mvn clean package install -DskipTests -Dgpg.skip=true | ||
- name: Install Junit5 bindings snapshot | ||
run: cd java/junit4 && mvn clean package install -DskipTests -Dgpg.skip=true | ||
- name: Install TestNG bindings snapshot | ||
run: cd java/testng && mvn clean package install -DskipTests -Dgpg.skip=true | ||
- name: Test with ${{ matrix.profile }} | ||
env: | ||
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} | ||
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} | ||
run: cd java/test-project && mvn clean test -P${{ matrix.profile }} |
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,147 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.example</groupId> | ||
<artifactId>test-project</artifactId> | ||
<version>0.0.1</version> | ||
|
||
<properties> | ||
<surefire.parallel>20</surefire.parallel> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.titusfortner</groupId> | ||
<artifactId>selenium-logger</artifactId> | ||
<version>2.4.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.saucelabs</groupId> | ||
<artifactId>saucebindings-junit4</artifactId> | ||
<version>2.0.0-beta.2-SNAPSHOT</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.saucelabs</groupId> | ||
<artifactId>saucebindings-testng</artifactId> | ||
<version>2.0.0-beta.2-SNAPSHOT</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.saucelabs</groupId> | ||
<artifactId>saucebindings-junit5</artifactId> | ||
<version>2.0.0-beta.2-SNAPSHOT</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.saucelabs</groupId> | ||
<artifactId>sauce_bindings</artifactId> | ||
<version>2.0.0-beta.2-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>junit4</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit47</artifactId> | ||
<version>3.5.2</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<includes> | ||
<include>**/junit4/**</include> | ||
</includes> | ||
<systemPropertyVariables> | ||
<sauce.enabled>true</sauce.enabled> | ||
</systemPropertyVariables> | ||
<parallel>all</parallel> | ||
<threadCountMethods>${surefire.parallel}</threadCountMethods> | ||
<useUnlimitedThreads>true</useUnlimitedThreads> | ||
<redirectTestOutputToFile>false</redirectTestOutputToFile> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>junit5</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<sauce.enabled>true</sauce.enabled> | ||
</systemPropertyVariables> | ||
<includes> | ||
<include>**/junit5/**</include> | ||
</includes> | ||
<properties> | ||
<configurationParameters> | ||
junit.jupiter.execution.parallel.enabled = true | ||
junit.jupiter.execution.parallel.mode.default = concurrent | ||
junit.jupiter.execution.parallel.config.strategy = fixed | ||
junit.jupiter.execution.parallel.config.fixed.parallelism = ${surefire.parallel} | ||
junit.jupiter.execution.parallel.config.fixed.max-pool-size = ${surefire.parallel} | ||
</configurationParameters> | ||
</properties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>testng</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-testng</artifactId> | ||
<version>3.5.2</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<sauce.enabled>true</sauce.enabled> | ||
</systemPropertyVariables> | ||
<includes> | ||
<include>**/testng/**</include> | ||
</includes> | ||
<parallel>methods</parallel> | ||
<threadCount>50</threadCount> | ||
<redirectTestOutputToFile>false</redirectTestOutputToFile> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
java/test-project/src/test/java/com/exampleservice/junit4/AccountPageTest.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,77 @@ | ||
package com.exampleservice.junit4; | ||
|
||
import com.exampleservice.pageobjects.NavBar; | ||
import com.exampleservice.pageobjects.user.AccountPage; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.openqa.selenium.WebDriverException; | ||
|
||
public class AccountPageTest extends BaseTest { | ||
private AccountPage accountPage; | ||
|
||
@Before | ||
public void navigate() { | ||
accountPage = new AccountPage(driver); | ||
accountPage.open(); | ||
} | ||
|
||
@Category(ContentTests.class) | ||
@Test | ||
public void pageCheck() { | ||
Assertions.assertDoesNotThrow( | ||
() -> accountPage.validateContent("manage your profile, favorites and orders")); | ||
} | ||
|
||
@Category(ContentTests.class) | ||
@Test | ||
public void hasNavBar() { | ||
try { | ||
new NavBar(driver).isDisplayed(); | ||
} catch (WebDriverException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Category(NavigationTests.class) | ||
@Test | ||
public void navigateToFavorites() { | ||
try { | ||
accountPage.navigateToFavorites(); | ||
} catch (WebDriverException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Category(NavigationTests.class) | ||
@Test | ||
public void navigateToProfile() { | ||
try { | ||
accountPage.navigateToProfile(); | ||
} catch (WebDriverException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Category(NavigationTests.class) | ||
@Test | ||
public void navigateToInvoices() { | ||
try { | ||
accountPage.navigateToInvoices(); | ||
} catch (WebDriverException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Category(NavigationTests.class) | ||
@Test | ||
public void navigateToMessages() { | ||
try { | ||
accountPage.navigateToMessages(); | ||
} catch (WebDriverException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
java/test-project/src/test/java/com/exampleservice/junit4/BaseTest.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,58 @@ | ||
package com.exampleservice.junit4; | ||
|
||
import com.saucelabs.saucebindings.SauceSession; | ||
import com.saucelabs.saucebindings.junit4.SauceBindingsWatcher; | ||
import java.time.Duration; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
|
||
public class BaseTest { | ||
WebDriver driver; | ||
SauceSession session; | ||
|
||
@Rule | ||
public SauceBindingsWatcher sauceWatcher = | ||
SauceBindingsWatcher.builder().withCapabilities(getChromeOptions()).build(); | ||
|
||
@Rule public TestWatcher localWatcher = new LocalTestWatcher(); | ||
|
||
@Before | ||
public void storeVariables() { | ||
this.session = sauceWatcher.getSession(); | ||
this.driver = | ||
SauceSession.isEnabled() ? sauceWatcher.getDriver() : new ChromeDriver(getChromeOptions()); | ||
} | ||
|
||
private ChromeOptions getChromeOptions() { | ||
ChromeOptions options = new ChromeOptions(); | ||
options.setImplicitWaitTimeout(Duration.ofSeconds(2)); | ||
return options; | ||
} | ||
|
||
public interface ContentTests {} | ||
|
||
public interface NavigationTests {} | ||
|
||
public interface FeatureTests {} | ||
|
||
private class LocalTestWatcher extends TestWatcher { | ||
@Override | ||
protected void failed(Throwable e, Description description) { | ||
if (!SauceSession.isEnabled()) { | ||
driver.quit(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void succeeded(Description description) { | ||
if (!SauceSession.isEnabled()) { | ||
driver.quit(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.