Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
jochen-testingbot committed Sep 9, 2024
1 parent ec65a00 commit fd8b568
Show file tree
Hide file tree
Showing 11 changed files with 3,353 additions and 113 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: NodeJS Tests

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: npm ci
- run: npm run build --if-present
- run: npm single
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.orig
reports
node_modules
.DS_Store
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[![Build Status](https://travis-ci.org/testingbot/nightwatch-example.svg?branch=master)](https://travis-ci.org/testingbot/nightwatch-example)

## TestingBot - NightWatch Example

TestingBot provides an online grid of browsers and mobile devices to run Automated tests on via Selenium WebDriver.
This example demonstrates how to use NightWatwch to run a test in parallel across several browsers.
TestingBot offers an online grid of browsers and mobile devices for running automated tests using Nightwatch.
This example repository demonstrates how to use Nightwatch to execute tests in parallel across multiple browsers on TestingBot.

### Environment Setup

Expand All @@ -16,29 +14,32 @@ This example demonstrates how to use NightWatwch to run a test in parallel acros
2. TestingBot Credentials
* In the terminal export your TestingBot Credentials as environmental variables:
```
$ export TB_KEY=<your TestingBot Key>
$ export TB_SECRET=<your TestingBot Secret>
$ export TESTINGBOT_KEY=<your TestingBot Key>
$ export TESTINGBOT_SECRET=<your TestingBot Secret>
```
3. Project Dependencies
* Install Node modules
```
$ npm install
```
### Running Tests
* Run one test:
```
$ npm run single
```
* Tests in Parallel:
```
$ ./node_modules/.bin/nightwatch -e chrome,firefox,internet_explorer_edge tests
$ npm run parallel
```
You will see the test result in the [TestingBot Dashboard](https://testingbot.com/members/)
### Resources
##### [TestingBot Documentation](https://testingbot.com/support/getting-started/nightwatch.html)
##### [TestingBot Nightwatch Documentation](https://testingbot.com/support/getting-started/nightwatch.html)
##### [SeleniumHQ Documentation](http://www.seleniumhq.org/docs/)
##### [NightWatch Documentation](http://nightwatchjs.org/)
##### [NightWatch Documentation](http://nightwatchjs.org/)
13 changes: 6 additions & 7 deletions custom_commands/customTestingBotEnd.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
exports.command = function(callback) {
var TestingBot = require("testingbot-api");
const TestingBot = require("testingbot-api");

var tb = new TestingBot({
const tb = new TestingBot({
api_key: process.env.TB_KEY,
api_secret: process.env.TB_SECRET
});

var sessionid = this.capabilities['webdriver.remote.sessionid'],
const sessionid = this.capabilities['webdriver.remote.sessionid'],
jobName = this.currentTest.name,
passed = this.currentTest.results.testcases[jobName].failed === 0;


console.log("TestingBotSessionId=" + sessionid);

var self = this
tb.updateTest({
'test[success]': passed,
'test[name]': jobName
}, sessionid, function () {
self.end(callback)
}, sessionid, () => {
this.end(callback)
});
};
};
26 changes: 26 additions & 0 deletions environments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
test_settings: {
default: {},
env1: {
desiredCapabilities: {
"browserName": "Chrome",
"browserVersion": "latest",
"platformName": "Windows 11"
}
},
env2: {
desiredCapabilities: {
"browserName": "Firefox",
"browserVersion": "latest",
"platformName": "Windows 11"
}
},
env3: {
desiredCapabilities: {
"browserName": "Safari",
"browserVersion": "17",
"platformName": "macOS Sonoma"
}
}
}
};
84 changes: 77 additions & 7 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,79 @@
module.exports = (function(settings) {
if (process.env.SELENIUM_HOST) {
settings.selenium.host = process.env.SELENIUM_HOST;
const additonalEnvironments = require("./environments");

if (!additonalEnvironments.test_settings)
additonalEnvironments.test_settings = {};

const testingBotOptions = {
'tb:options' : {
"build" : "nightwatch-example",
"name" : "Nightwatch Example Test",
"seleniumVersion" : "4.24.0",
username: '${TESTINGBOT_KEY}' || 'YOUR_USERNAME',
accessKey: '${TESTINGBOT_SECRET}' || 'YOUR_ACCESS_KEY',
},
}

const testingBot = {
webdriver: {
start_process: false,
timeout_options: {
timeout: 120000,
retry_attempts: 3
},
keep_alive: true
},

selenium: {
host: 'hub.testingbot.com',
port: 443
},

desiredCapabilities: {
browserName: 'chrome',
...testingBotOptions
}
if (process.env.SELENIUM_PORT) {
settings.selenium.host = process.env.SELENIUM_PORT;
}

const nightwatchConfigs = {
src_folders: ['tests'],
custom_commands_path: 'custom_commands',
output_folder: 'reports',
live_output: true,

test_settings: {
default: {
launch_url: 'https://nightwatchjs.org'
},

"testingbot.chrome": {
...testingBot,
desiredCapabilities:{
browserName: 'chrome',
...testingBotOptions
}
},
"testingbot.firefox": {
...testingBot,
desiredCapabilities:{
browserName: 'firefox',
...testingBotOptions
}
},
"testingbot.edge": {
...testingBot,
desiredCapabilities:{
browserName: 'Edge',
...testingBotOptions
}
}
}
return settings;
})(require('./nightwatch.json'));
}

for (let key in additonalEnvironments.test_settings) {
nightwatchConfigs.test_settings[key] = {
...testingBot,
...additonalEnvironments.test_settings[key]
};
}

module.exports = nightwatchConfigs;
68 changes: 0 additions & 68 deletions nightwatch.json

This file was deleted.

Loading

0 comments on commit fd8b568

Please sign in to comment.