Skip to content

Commit 85f6129

Browse files
initial commit
0 parents  commit 85f6129

File tree

8 files changed

+223
-0
lines changed

8 files changed

+223
-0
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Maven Build and Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
env:
9+
TESTINGBOT_KEY: ${{ secrets.TESTINGBOT_KEY }}
10+
TESTINGBOT_SECRET: ${{ secrets.TESTINGBOT_SECRET }}
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Set up JDK
16+
uses: actions/setup-java@v2
17+
with:
18+
distribution: 'adopt'
19+
java-version: '11'
20+
21+
- name: Cache Maven dependencies
22+
uses: actions/cache@v2
23+
with:
24+
path: |
25+
~/.m2/repository
26+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
27+
restore-keys: |
28+
${{ runner.os }}-maven-
29+
30+
- name: Build and test with Maven
31+
run: mvn clean test

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12+
hs_err_pid*
13+
.idea/
14+
target/
15+
*.iml
16+
17+
.DS_Store

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## TestingBot - Java, TestNG & Cucumber
2+
3+
TestingBot provides an online grid of browsers and mobile devices to run Automated tests on via Selenium WebDriver.
4+
This example demonstrates how to use Java with TestNG and Cucumber to run tests across several browsers.
5+
6+
### Environment Setup
7+
8+
1. Global Dependencies
9+
* [Install Maven](https://maven.apache.org/install.html)
10+
* Or Install Maven with [Homebrew](http://brew.sh/)
11+
```
12+
$ brew install maven
13+
```
14+
15+
2. TestingBot Credentials
16+
* Add your TestingBot Key and Secret as environmental variables. You can find these in the [TestingBot Dashboard](https://testingbot.com/members/).
17+
```
18+
$ export TESTINGBOT_KEY=<your TestingBot Key>
19+
$ export TESTINGBOT_SECRET=<your TestingBot Secret>
20+
```
21+
22+
### Running Tests
23+
24+
* To start an example test, please run this command:
25+
```
26+
$ mvn test
27+
```
28+
You will see the test result in the [TestingBot Dashboard](https://testingbot.com/members/)
29+
30+
### Resources
31+
##### [TestingBot Documentation](https://testingbot.com/support/)
32+
33+
##### [SeleniumHQ Documentation](http://www.seleniumhq.org/docs/)
34+
35+
##### [TestNg Documentation](https://testng.org/doc/index.html)

pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>testingbot-testng-cucumber</artifactId>
6+
<groupId>com.testingbot</groupId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<name>testingbot_cucmber_testng</name>
10+
<description>An example project to run Cucumber + TestNG tests on TestingBot's browser grid</description>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>io.cucumber</groupId>
15+
<artifactId>cucumber-java</artifactId>
16+
<version>7.18.1</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>io.cucumber</groupId>
20+
<artifactId>cucumber-testng</artifactId>
21+
<version>7.18.1</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.testng</groupId>
25+
<artifactId>testng</artifactId>
26+
<version>7.10.2</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.seleniumhq.selenium</groupId>
31+
<artifactId>selenium-java</artifactId>
32+
<version>4.24.0</version>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>3.0</version>
42+
<configuration>
43+
<source>1.7</source>
44+
<target>1.7</target>
45+
</configuration>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-surefire-plugin</artifactId>
50+
<version>2.12.4</version>
51+
<configuration>
52+
<parallel>classes</parallel>
53+
<threadCount>40</threadCount>
54+
<redirectTestOutputToFile>false</redirectTestOutputToFile>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.testingbotdemo.selenium.cucumber.definitions;
2+
3+
import io.cucumber.java.en.Given;
4+
import io.cucumber.java.en.Then;
5+
import io.cucumber.java.en.When;
6+
import org.openqa.selenium.By;
7+
import org.testng.Assert;
8+
import com.testingbotdemo.selenium.cucumber.drivers.TestingBotDriver;
9+
import org.openqa.selenium.WebDriver;
10+
11+
public class StepDefinitions {
12+
WebDriver driver = TestingBotDriver.getDriver();
13+
14+
@Given("I open Google")
15+
public void i_open_google() {
16+
driver.get("https://www.google.com");
17+
}
18+
19+
@When("I search for {string}")
20+
public void i_search_for(String query) {
21+
driver.findElement(By.name("q")).sendKeys(query);
22+
driver.findElement(By.name("btnK")).submit();
23+
}
24+
25+
@Then("I should see results")
26+
public void i_should_see_results() {
27+
Assert.assertTrue(driver.getTitle().contains("Google"));
28+
driver.quit();
29+
}
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.testingbotdemo.selenium.cucumber.drivers;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.remote.DesiredCapabilities;
5+
import org.openqa.selenium.remote.RemoteWebDriver;
6+
import java.net.URL;
7+
import java.net.MalformedURLException;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
public class TestingBotDriver {
12+
13+
public static WebDriver getDriver() {
14+
String username = System.getenv("TESTINGBOT_KEY") == null ? "TESTINGBOT_KEY" : System.getenv("TESTINGBOT_KEY");
15+
String accesskey = System.getenv("TESTINGBOT_SECRET") == null ? "TESTINGBOT_SECRET" : System.getenv("TESTINGBOT_SECRET");
16+
17+
DesiredCapabilities capabilities = new DesiredCapabilities();
18+
capabilities.setCapability("browserName", "chrome");
19+
capabilities.setCapability("browserVersion", "latest");
20+
capabilities.setCapability("platformName", "WIN10");
21+
22+
Map<String, Object> testingBotOptions = new HashMap<>();
23+
testingBotOptions.put("name", "Cucumber Example");
24+
capabilities.setCapability("tb:options", testingBotOptions);
25+
26+
try {
27+
String gridURL = "https://" + username + ":" + accesskey + "@hub.testingbot.com/wd/hub";
28+
return new RemoteWebDriver(new URL(gridURL), capabilities);
29+
} catch (MalformedURLException e) {
30+
e.printStackTrace();
31+
throw new RuntimeException("Invalid URL provided for TestingBot hub", e);
32+
}
33+
}
34+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.testingbotdemo.selenium.cucumber.runners;
2+
3+
import io.cucumber.testng.AbstractTestNGCucumberTests;
4+
import io.cucumber.testng.CucumberOptions;
5+
6+
@CucumberOptions(
7+
features = "src/test/resources/features",
8+
glue = "com.testingbotdemo.selenium.cucumber.definitions"
9+
)
10+
public class TestRunner extends AbstractTestNGCucumberTests {
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Example feature
2+
3+
Scenario: Open Google and search
4+
Given I open Google
5+
When I search for "TestNG and Cucumber"
6+
Then I should see results

0 commit comments

Comments
 (0)