Skip to content

Commit

Permalink
get selenium tests passing with latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Oct 17, 2023
1 parent 6342f0d commit 525eb98
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/selenium-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Run tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
Expand Down
55 changes: 29 additions & 26 deletions selenium-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,46 @@
<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">
<parent>
<artifactId>demo-java</artifactId>
<groupId>com.saucelabs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>selenium-examples</artifactId>
<groupId>com.com.saucelabs</groupId>
<artifactId>selenium_examples</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Sauce Labs Selenium Examples</name>
<description>Example code for using Selenium on Sauce labs</description>
<url>https://github.com/saucelabs-training/demo-java</url>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<surefire.parallel>1</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.saucelabs</groupId>
<artifactId>saucebindings-junit5</artifactId>
<version>1.0.0</version>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.deque.html.axe-core</groupId>
<artifactId>selenium</artifactId>
<version>4.4.0</version>
<version>4.14.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.4</version>
<groupId>com.titusfortner</groupId>
<artifactId>selenium-logger</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -41,22 +51,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<PARALLELISM>20</PARALLELISM>
<MINIMUM_RUNNABLE>20</MINIMUM_RUNNABLE>
<MAX_POOL_SIZE>20</MAX_POOL_SIZE>
<CORE_POOL_SIZE>20</CORE_POOL_SIZE>
</systemPropertyVariables>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.strategy = custom
junit.jupiter.execution.parallel.config.custom.class = com.saucelabs.saucebindings.junit5.CustomStrategy
junit.jupiter.execution.parallel.config.fixed.parallelism = ${surefire.parallel}
junit.jupiter.execution.parallel.config.fixed.max-pool-size = ${surefire.parallel}
</configurationParameters>
</properties>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void performanceLog() {
metricsLog.put("type", "sauce:performance");
Map<String, Object> metrics = (Map<String, Object>) driver.executeScript("sauce:log", metricsLog);

Assertions.assertTrue((int) metrics.get("firstInteractive") < 5000 );
Assertions.assertTrue((long)metrics.get("firstInteractive") < 5000 );
}

@DisplayName("Get jankiness metrics from previous navigation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public void sauceDemoAccessibility() {
public void abcdcomputechTest() {
driver.navigate().to("http://abcdcomputech.dequecloud.com");
Results results = session.getAccessibilityResults();
Assertions.assertEquals(7, results.getViolations().size());
Assertions.assertEquals(8, results.getViolations().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.HasExtensions;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.LocalFileDetector;
Expand All @@ -22,13 +23,15 @@ public SauceOptions createSauceOptions() {
public void addons() {
driver.setFileDetector(new LocalFileDetector());
WebDriver augmentedDriver = new Augmenter().augment(driver);
String id = ((HasExtensions) augmentedDriver).installExtension(Paths.get("src/test/resources/ninja_saucebot-1.0-an+fx.xpi"));
String id = ((HasExtensions) augmentedDriver).installExtension(Paths.get("src/test/resources/selenium-example.xpi"));

driver.get("https://www.saucedemo.com");
Assertions.assertTrue(driver.findElements(By.className("bot_column2")).size() > 0);
WebElement injected = driver.findElement(By.id("webextensions-selenium-example"));
Assertions.assertEquals("Content injected by webextensions-selenium-example", injected.getText());

((HasExtensions) augmentedDriver).uninstallExtension(id);

driver.navigate().refresh();
Assertions.assertEquals(0, driver.findElements(By.className("bot_column2")).size());
Assertions.assertEquals(0, driver.findElements(By.id("webextensions-selenium-example")).size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ public void edgeExecution() {
driver.findElement(By.cssSelector("input[type=submit]")).click();

Assertions.assertEquals(1, driver.getWindowHandles().size());
driver.quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ViewPageChromeTest extends SauceBaseTest {
public SauceOptions createSauceOptions() {
ChromeOptions options = new ChromeOptions();
// note: headless only actually required for print page
options.setHeadless(true);
options.addArguments("--headless=new");

return SauceOptions.chrome(options).build();
}
Expand All @@ -29,6 +29,7 @@ public void printPage() throws IOException {
driver.navigate().to("https://www.saucedemo.com/v1/inventory.html");

Path printPage = Paths.get(directory + "PrintPageChrome.pdf");
printPage.toFile().deleteOnExit();
Pdf print = driver.print(new PrintOptions());

Files.write(printPage, OutputType.BYTES.convertFromBase64Png(print.getContent()));
Expand All @@ -39,7 +40,8 @@ public void takeScreenshot() throws IOException {
driver.navigate().to("https://www.saucedemo.com/v1/inventory.html");
byte[] screenshotAs = driver.getScreenshotAs(OutputType.BYTES);

Path screenshot = Paths.get(directory + "TakeScreenshotChrome.png");
Path screenshot = Paths.get(directory + "FirefoxScreenshotChrome.png");
screenshot.toFile().deleteOnExit();
Files.write(screenshot, screenshotAs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ public void navigate() {
@Test
public void printPage() throws IOException {

Path printPage = Paths.get(directory + "PrintPageFirefox.pdf");
Path printPage = Paths.get(directory + "FirefoxPrintPage.pdf");
printPage.toFile().deleteOnExit();
Pdf print = driver.print(new PrintOptions());

Files.write(printPage, OutputType.BYTES.convertFromBase64Png(print.getContent()));
}

@Test
public void takeScreenshot() throws IOException {

Path screenshot = Paths.get(directory + "TakeScreenshotFirefox.png");
Path screenshot = Paths.get(directory + "FirefoxScreenshot.png");
screenshot.toFile().deleteOnExit();
byte[] screenshotAs = driver.getScreenshotAs(OutputType.BYTES);

Files.write(screenshot, screenshotAs);
Expand All @@ -55,7 +56,8 @@ public void takeFullPageScreenshot() throws IOException {
WebDriver augmentedDriver = new Augmenter().augment(driver);
File file = ((HasFullPageScreenshot) augmentedDriver).getFullPageScreenshotAs(OutputType.FILE);

Path fullPageScreenshot = Paths.get(directory + "TakeFullPageScreenshotFirefox.png");
Path fullPageScreenshot = Paths.get(directory + "FirefoxFullPageScreenshot.png");
fullPageScreenshot.toFile().deleteOnExit();
Files.move(file.toPath(), fullPageScreenshot);
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 525eb98

Please sign in to comment.