Skip to content

Commit

Permalink
#3 Sauce labs configuration (#66)
Browse files Browse the repository at this point in the history
* Some minor documentation updates

* Initial commit of the changes needed to integrsate ssaucelabs to the framework

* Fixing some codacy complaints

* Removing Codacy

* Configuring SonarCloud

* Fixing travis

* Addressing SonarCloud issues and switching up project badges

* Fixing some unit test issued

* Moving ITs to Ts

* Adding some more tests for the webdriver utils

* Adding more tests

* Removing some unneeded comments

* Adding saucelabs username to build badge
  • Loading branch information
stevewalton28 authored Nov 30, 2020
1 parent 3ab6a09 commit 39f9a92
Show file tree
Hide file tree
Showing 54 changed files with 1,407 additions and 548 deletions.
11 changes: 0 additions & 11 deletions .codacy.yml

This file was deleted.

30 changes: 4 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dist: trusty
language: java
jdk:
- openjdk13
git:
depth: false
cache:
directories:
- "$HOME/.m2"
Expand All @@ -10,8 +12,6 @@ before_script:
- sh -e /etc/init.d/xvfb start
- sleep 3
before_install:
- openssl aes-256-cbc -K $encrypted_25a884814f46_key -iv $encrypted_25a884814f46_iv
-in deployment/signingkey.asc.enc -out deployment/signingkey.asc -d
- cp .travis.settings.xml $HOME/.m2/settings.xml
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile
--background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
Expand All @@ -21,32 +21,10 @@ before_install:
addons:
firefox: latest
install:
- mvn clean install -Dmaven.javadoc.skip=true -B -V
- mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- bash scripts/get-bank-holiday-data-source-and-store-in-resources.sh
after_success:
- gpg2 --keyring=$TRAVIS_BUILD_DIR/pubring.gpg --no-default-keyring --import deployment/signingkey.asc
- gpg2 --allow-secret-key-import --keyring=$TRAVIS_BUILD_DIR/secring.gpg --no-default-keyring
--import deployment/signingkey.asc
- mvn clean deploy -Dgpg.executable=gpg2 -Dgpg.keyname=5F84CD1775351968CABF0B0D779D2423E1D24D89
-Dgpg.passphrase=$GPG_PASSPHRASE -Dgpg.publicKeyring=$TRAVIS_BUILD_DIR/pubring.gpg -Dgpg.secretKeyring=$TRAVIS_BUILD_DIR/secring.gpg
deploy:
- provider: script
script: mvn test com.gavinmogan:codacy-maven-plugin:coverage -DcoverageReportFile=target/site/jacoco/jacoco.xml
-DprojectToken=$CODACY_PROJECT_TOKEN -DapiToken=$CODACY_API_TOKEN
on:
branch: master
- provider: script
script: bash scripts/publish-javadocs-to-github-pages.sh
on:
tags: true
- provider: script
script:
- mvn release:prepare
- mvn release:perform
on:
tags: true
env:
global:
- secure: cM73yz9Rj/wlGB+iIKnerkMhOH6dwMw97e0eNN8qIaA3x6Wp9JGwLOkctQTkOB3HgTsaO6I6/eIWylb8bzdQhu08zZvEmAGr8MXSRNtQm5l2zdx4uovwp8VAr2DBFmk1uyOXErwqsTo7ofSkjDcjNN57XR28frFYAuYAqa0+M9hMC4PWkawI22k9LgLA8LtR0Yzkto8eH1bw74YPMXhjjBZ6b/BTUqAOkwWbGujUmLtT7VeEMxKGJwgyoCw2+UKRtdAU+/E0LCAU2DuxYTtn00Om7GDV5eXZu58s+mRLMRG2038U/Bam4dTy6ZNrKjHlR3l3yyhSKKarG6st7cHvqYI2eaHi6L205o9RI4jqihIfPhxX2AtYGimSrQzHEvrc2hXqM4oqqT8xM6BCRIGfBmImUikBh3d+MubFXlne/mEPyq+csDer3Waz0sD2OrxtPjIKUGAltH61g/Wy54L4IVd5KzhX65lddYRMTyALyiTzWmYDmfD/IvhPOurjz4GU4FiNbBxiihKgc4FPFXWPRJVMu5Hb20b4g4RungBFtyBxw24VzwOaMOz7d9K8bR2NMydT/QaaLG3OQvTkO/2xQN00ddy1KJ7O7S1MGRJFq5ZEUjvUDAeRAANY86GVMk4lKh2U6EJo21hhADGWqqAuCo6fhyrVprExEAAk1OMc6A8=
- secure: I4fr21xrDzmh22zAD1xmEYlo/KOZmFz1khuUb/QfMxARLHn6+voYQdULOHS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wy8PJoDKVXJjW7PbYMBwGKnOu7QFG7LrLVCM7zORHfg+iu317yFdZLF+Jn+mBu5WGY+Jgr3rJnkgC7s5mQ+KKrWeFc/fZirykC8RbCkuss5KeQvkIiLtExvHP/1jPld/mhM2ItfCR6REVwHCN7zBYK56S8fa+oxT4ozc2p6Ked/F+QrrS0LekWcS0QnWYD5/Bp0iJVjL1HMv0vOKJimbmSf2athuFGA1gkTpBPKG7opSZf58=
tags: true
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# selenium-pom-framework
[![Build Status](https://travis-ci.com/digital-delivery-academy/selenium-pom-framework.svg?branch=master)](https://travis-ci.com/digital-delivery-academy/selenium-pom-framework)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/98cb1cb4ac7a4061b8677ffb246cc963)](https://www.codacy.com/gh/digital-delivery-academy/selenium-pom-framework?utm_source=github.com&utm_medium=referral&utm_content=digital-delivery-academy/selenium-pom-framework&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/98cb1cb4ac7a4061b8677ffb246cc963)](https://www.codacy.com/gh/digital-delivery-academy/selenium-pom-framework?utm_source=github.com&utm_medium=referral&utm_content=digital-delivery-academy/selenium-pom-framework&utm_campaign=Badge_Coverage)
[![Sauce Test Status](https://saucelabs.com/buildstatus/YOUR_SAUCE_USERNAME)](https://app.saucelabs.com/u/stevewalton)
[![GitHub Issues badge](https://img.shields.io/github/issues-raw/digital-delivery-academy/selenium-pom-framework?color=green)](https://github.com/digital-delivery-academy/selenium-pom-framework/issues)
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)

[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=digital-delivery-academy_selenium-pom-example&metric=coverage)](https://sonarcloud.io/dashboard?id=digital-delivery-academy_selenium-pom-example)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=digital-delivery-academy_selenium-pom-example&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=digital-delivery-academy_selenium-pom-example)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=digital-delivery-academy_selenium-pom-example&metric=security_rating)](https://sonarcloud.io/dashboard?id=digital-delivery-academy_selenium-pom-example)
[![Sauce Test Status](https://saucelabs.com/buildstatus/stevewalton)](https://app.saucelabs.com/u/stevewalton)

[![Latest version badge](https://img.shields.io/github/v/release/digital-delivery-academy/selenium-pom-framework)](https://github.com/digital-delivery-academy/selenium-pom-framework/releases)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<!-- ALL-CONTRIBUTORS-BADGE:END -->

**We've released version 1.0.0! And we've moved to Maven Central hosting and added instrumentation**

This toolkit is really a culmination of 10 years of working with teams building automated UI checks with Selenium. We've found time and again that we refactor or rewrite "frameworks" that wrap the entirity of the Selenium API (to little benefit). On top of this, we see so much brittle code that we wanted to put something out there that people could use and benefit from our experience. As a result, this toolkit provides an simple, lightweight (and well structured) way to launch, control and configure checks for Selenium/WebDriver in Java. It's a curation of all of the little libraries and fixes we've used over the years. So if you're at the start of your automation journey or you're just bored of writing the same "framework" over and over again, you're in the right place.
This toolkit is really a culmination of 10 years of working with teams building automated UI checks with Selenium. We've found time and again that we refactor or rewrite "frameworks" that wrap the entirety of the Selenium API (to little benefit). On top of this, we see so much brittle code that we wanted to put something out there that people could use and benefit from our experience. As a result, this toolkit provides an simple, lightweight (and well structured) way to launch, control and configure checks for Selenium/WebDriver in Java. It's a curation of all of the little libraries and fixes we've used over the years. So if you're at the start of your automation journey or you're just bored of writing the same "framework" over and over again, you're in the right place.

You'll find no junk (hopefully) here, but it's a fairly opinionated approach:
- There's no mass "wrapper" on Selenium - that's dumb
- We suggest using the Page Object Model, it's generally a good idea and we provide a starting point for this
- We suggest using the Page Object Model, it's generally a good idea, and we provide a starting point for this
- We resolve Driver binaries from WebDriverManager (https://github.com/bonigarcia/webdrivermanager)
- We provide random test data generators from Mockneat (https://github.com/nomemory/mockneat) and UK Gov (https://github.com/dwp/nino-format-validation) as well as some of our own (for dates and stuff)
- There's an externalised (and overridable) configuration system, based on JSON
Expand Down
23 changes: 9 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@
<javadoc.maven.plugin.version>3.1.1</javadoc.maven.plugin.version>
<joda.time.version>2.7</joda.time.version>
<restassured.version>4.2.0</restassured.version>
<saucelabs.bindings>1.0.0</saucelabs.bindings>
<dropwizard.metrics.version>4.1.2</dropwizard.metrics.version>
<sonar.projectKey>digital-delivery-academy_selenium-pom-example</sonar.projectKey>
<sonar.organization>digital-delivery-academy</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<dependencies>
Expand Down Expand Up @@ -193,6 +197,11 @@
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_bindings</artifactId>
<version>${saucelabs.bindings}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand All @@ -214,20 +223,6 @@
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.version}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand Down
16 changes: 16 additions & 0 deletions saucelabs-fs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"acceptInsecureCerts": true,
"strictFileInteractability": true,
"capturePerformance": true,
"extendedDebugging": false,
"recordLogs": true,
"recordScreenshots": true,
"recordVideo": true,
"saucePlatform": "WINDOWS_10",
"browserName": "CHROME",
"browserVersion": "LATEST",
"pageLoadStrategy": "NORMAL",
"seleniumVersion": "3.7.1",
"sauceLabsRemoteGridUrl": "https://ondemand.saucelabs.com/wd/hub",
"unhandledPromptBehaviour": "DISMISS"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh

curl https://www.gov.uk/bank-holidays.json --output src/main/resources/bank-holidays.json
echo "STEVE STEVE STEVE"
ls src/main/resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.co.evoco.exceptions;

public class SauceLabsCredentialsException extends Exception {

public SauceLabsCredentialsException() {
super("Tried to get credentials from system variable SAUCE_USERNAME and SAUCE_ACCESS_KEY but could not find them");
throw new RuntimeException("Can't execute against SauceLabs without valid credentials being provided, see stack trace from SauceLabsCredentialsException");
}
}
4 changes: 1 addition & 3 deletions src/main/java/uk/co/evoco/pageobjects/BasePageObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public abstract class BasePageObject {
* instance available to child classes.
* @param webDriver active WebDriver instance
*/
public BasePageObject(WebDriver webDriver) {
protected BasePageObject(WebDriver webDriver) {
PageFactory.initElements(webDriver, this);
this.webDriver = webDriver;
this.wait = new WebDriverWait(this.webDriver, TestConfigHelper.get().getWebDriverWaitTimeout());
}

// TODO: fill() submit()
}
2 changes: 1 addition & 1 deletion src/main/java/uk/co/evoco/testdata/BankHoliday.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public LocalDate getLocalDate() {

@JsonProperty("date")
public void setLocalDate(String localDate) {
this.localDate = new LocalDate().parse(localDate);
this.localDate = LocalDate.parse(localDate);
}
}
57 changes: 57 additions & 0 deletions src/main/java/uk/co/evoco/tests/BaseAbstractSauceLabsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package uk.co.evoco.tests;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import uk.co.evoco.exceptions.SauceLabsCredentialsException;
import uk.co.evoco.webdriver.WebDriverListener;
import uk.co.evoco.webdriver.configuration.TestConfigHelper;
import uk.co.evoco.webdriver.configuration.driver.ConfiguredDriver;
import uk.co.evoco.webdriver.configuration.driver.ConfiguredSauceLabsGridDriver;

import java.io.IOException;

/**
* BaseAbstractTest to handle things that testers shouldn't need to worry about (like starting up a WebDriver instance
* and getting everything in the right space for consumers to run tests that are correctly configured etc).
*/
public abstract class BaseAbstractSauceLabsTest {

protected EventFiringWebDriver webDriver;

/**
* This will run before every test class.
* This method gets the configuration and constructs the WebDriver instance, the screenshot
* directory and the makes these items accessible.
*/
@BeforeAll
public static void beforeAll() {
// Do nothing
}

/**
* This will run before EVERY @Test that extends this class
* The method will create a new instance of WebDriver and a browser and open Google.com
* This ensures we always have a fresh browser window and a guaranteed starting point
* @throws IOException if results directory isn't created or config file cannot be found
*/
@BeforeEach
public void setUp() throws SauceLabsCredentialsException {
ConfiguredDriver sauceLabsDriver = new ConfiguredSauceLabsGridDriver();
this.webDriver = new EventFiringWebDriver(sauceLabsDriver.getRemoteDriver());
this.webDriver.register(new WebDriverListener());
this.webDriver.get(TestConfigHelper.get().getBaseUrl());
this.webDriver.manage().window().maximize();
}

/**
* This will run after EVERY @Test that extends this class
* The method will close the current browser and WebDriver instance down
* This ensures we have cleaned up after ourselves (this happens even if the test fails)
*/
@AfterEach
public void tearDown() {
this.webDriver.quit();
}
}
3 changes: 2 additions & 1 deletion src/main/java/uk/co/evoco/tests/BaseAbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* and getting everything in the right space for consumers to run tests that are correctly configured etc).
*/
public abstract class BaseAbstractTest {

protected EventFiringWebDriver webDriver;
protected static ResultsManager resultsManager;

Expand All @@ -38,7 +39,7 @@ public static void beforeAll() {
@BeforeEach
public void setUp() throws IOException {
this.webDriver = new WebDriverBuilder()
.setResultsDirectory(this.resultsManager.getScreenshotDirectory())
.setResultsDirectory(resultsManager.getScreenshotDirectory())
.build();
this.webDriver.get(TestConfigHelper.get().getBaseUrl());
this.webDriver.manage().window().maximize();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/uk/co/evoco/webdriver/WebDriverListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void setScreenshotDirectory(File screenshotDirectory) {
* @param webElement active WebElement, already located
* @param webDriver active WebDriver instance
*/
@Override
public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {
new WebDriverWait(webDriver,
TestConfigHelper.get().getWebDriverWaitTimeout()).until(
Expand All @@ -57,6 +58,7 @@ public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {
* @param webElement active WebElement, already located
* @param webDriver active WebDriver instance
*/
@Override
public void beforeClickOn(WebElement webElement, WebDriver webDriver) {
new WebDriverWait(webDriver,
TestConfigHelper.get().getWebDriverWaitTimeout()).until(
Expand All @@ -68,6 +70,7 @@ public void beforeClickOn(WebElement webElement, WebDriver webDriver) {
* @param throwable the thrown exception that we are holding here
* @param webDriver active WebDriver instance
*/
@Override
public void onException(Throwable throwable, WebDriver webDriver) {
try {
if(TestConfigHelper.get().isTakeScreenshotOnError()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

public class GraphiteConfig {

private boolean isEnabled = false;
private String host;
private int port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.URL;

public class GridConfig {

private URL gridUrl;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

public class JmxConfig {

private boolean isEnabled = false;

public boolean isEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
*/
public enum RunType {
LOCAL,
GRID
GRID,
SAUCELABS
}
Loading

0 comments on commit 39f9a92

Please sign in to comment.