saucelabs-training / demo-js Goto Github PK
View Code? Open in Web Editor NEWA repository containing examples using NodeJS with Sauce Labs
License: MIT License
A repository containing examples using NodeJS with Sauce Labs
License: MIT License
My customer came back and asked me for an implementation with the following requirements:
Just letting you know that I will be working on this. Let me know if you have any thoughts @wswebcreation
I was thinking of running my react unit/component tests on sauce cloud but most of the examples given here are based on e2e tests and I could not find any integrations of sauce with React anywhere. So is it a good idea to do this and if it is what method should be followed ?
Cannot reproduce the steps provided on README
Follow README steps
Change line 18, removing x from describe
Following a gif demonstrating the results after trying to reproduce the exact steps, using npm test command
Following a gif demonstrating the results after trying to reproduce the steps but running npx instead of npm test
Jasmine error running npm test command
Randomized with seed 05702
Started
No specs found
Finished in 0.001 seconds
Incomplete: No specs found
Randomized with seed 05702 (jasmine --random=true --seed=05702)
npm ERR! Test failed. See above for more details.
Jasmine error running npx command
Randomized with seed 78523
Started
Pending: 1) Instant Sauce Test Module 1 should-open-safari
No reason given
1 spec, 0 failures, 1 pending spec
Finished in 0.003 seconds
Randomized with seed 78523 (jasmine --random=true --seed=78523)
Mocha error running npm test command
Warning: Could not find any test files matching pattern: module1-mocha-test.js
No test files found
Mocha error running npx command
Instant Sauce Test Module 1
- should-open-safari
0 passing (4ms)
1 pending➜ mocha-examples git:(master) ✗ npx mocha ./test/module1-mocha-test.js
Instant Sauce Test Module 1
1) should-open-safari0 passing (73ms)
1 failing
- Instant Sauce Test Module 1
should-open-safari:
TypeError: Cannot read property 'state' of undefined
at Context. (test/module1-mocha-test.js:50:65)
at processImmediate (internal/timers.js:461:21)(node:9138) UnhandledPromiseRejectionWarning: WebDriverError: Uh oh, you've run out of minutes!
Please visit https://saucelabs.com/pricing to purchase a subscription.
at Object.checkLegacyResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:556:13)
at Executor.execute (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:491:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Usenode --trace-warnings ...
to show where the warning was created)
(node:9138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9138) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:9138) UnhandledPromiseRejectionWarning: WebDriverError: Uh oh, you've run out of minutes!
Please visit https://saucelabs.com/pricing to purchase a subscription.
at Object.checkLegacyResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:556:13)
at Executor.execute (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:491:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:9138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:9138) UnhandledPromiseRejectionWarning: WebDriverError: Uh oh, you've run out of minutes!
Please visit https://saucelabs.com/pricing to purchase a subscription.
at Object.checkLegacyResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:556:13)
at Executor.execute (/Users/palomaoliveira/Documents/testing/demo-js/on-boarding-modules/mocha-examples/node_modules/selenium-webdriver/lib/http.js:491:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:9138) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
Hi @wswebcreation. Was hoping you could help me with something when using your customSauceLabsEnd file for Nightwatch
I'm trying to get Nightwatch working to send the test name, and test status up to SauceLabs on completion of a test.
As you can see I'm getting an error:
Here's my relevant config:
nightwatch.conf.js
const nightwatchConfig = {
src_folders: ["./tests"],
output_folder: "./results/",
globals_path: "./common/global.js",
custom_commands_path: "./common/commands",
test_workers: {
enabled: true,
workers: "auto",
},
test_settings: {
default: {
// Not for direct use.
launch_url: BH.url("fe", ""),
desiredCapabilities: {
javascriptEnabled: true,
acceptSslCerts: true,
},
webdriver: {
start_process: true, // Run on local machine.
port: 4444,
},
},
saucelabs: {
// Saucelabs (not tunneled currently). Not for direct use.
live_output: true,
// plugins: ["nightwatch-saucelabs-endsauce"],
use_ssl: true,
timeZone: "New York",
desiredCapabilities: {
"sauce:options": {
// tunnelIdentifier: "tunnel1",
region: "us-west-1",
username: "${SAUCE_USERNAME}",
accessKey: "${SAUCE_ACCESS_KEY}",
screenResolution: "1920x1080",
// capturePerformance: true,
},
},
selenium: {
port: 443,
host: "ondemand.us-west-1.saucelabs.com",
start_process: false,
},
webdriver: {
port: 443,
host: "ondemand.us-west-1.saucelabs.com",
start_process: false,
},
globals: {
propertyData: {
saucelabs: true,
},
},
},
"browserstack.chrome": {
extends: "browserstack",
desiredCapabilities: {
browserName: "chrome",
},
},
}
./common/commands/customSauceLabsEnd.js
exports.command = async function () {
// 1. Require the `Saucelabs` npm module
const SauceLabs = require("saucelabs");
// 2. Instantiate the module
const myAccount = new SauceLabs.default({
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
region: "us",
});
// 3a. Get the sessionId
const sessionId = this.capabilities["webdriver.remote.sessionid"];
// 3b. Get the jobName
const jobName = this.currentTest.name;
// 3c. Get the status
const passed = this.currentTest.results.testcases[jobName].passed > 0;
// 4. Update the status in Sauce Labs
await myAccount.updateJob(process.env.SAUCE_USERNAME, sessionId, {
passed: passed,
});
// 5. Tell Nighwatch that we are done
return this.end();
};
./common/global.js
module.exports = {
before(cb) {
cb();
},
after(cb) {
cb();
},
beforeEach(browser, cb) {
cb();
},
afterEach(browser, cb) {
// browser.endSauce();
browser.customSauceLabsEnd();
browser.cb();
},
};
When running the provided instructions "npm install && npm test
", I arrive at tests which only pass for 2/6. I'm providing my credentials as SAUCE_USERNAME=USERNAME-HERE SAUCE_ACCESS_KEY=ACCESSKEY-HERE yarn test
yarn test
yarn run v1.17.3
$ mocha
async/await tests
Page Title is: Swag Labs
✓ get-title-test (1566ms)
URL is: https://www.saucedemo.com/inventory.html
✓ login-test (4763ms)
headless chrome test
1) "before each" hook for "get-title-test"
2) "after each" hook for "get-title-test"
headless firefox test
3) "before each" hook for "get-title-test"
4) "after each" hook for "get-title-test"
2 passing (21s)
4 failing
1) headless chrome test
"before each" hook for "get-title-test":
WebDriverError: Misconfigured -- Sauce Labs Authentication Error.
You used username 'dbsweets' and access key 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXe399738f' to authenticate, which are not valid Sauce Labs credentials.
The following desired capabilities were received:
{'browserName': 'chrome',
'browserVersion': 'latest',
'goog:chromeOptions': {'w3c': True},
'platformName': 'linux',
'sauce:options': {'accessKey': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXe399738f',
'build': 'Sample Headless Tests',
'idleTimeout': 1000,
'maxDuration': 3600,
'name': 'headless-chrome-test-js',
'seleniumVersion': '3.141.59',
'tags': ['sauceDemo',
'async',
'node',
'webdriverjs',
'headless'],
'username': 'dbsweets'}}
at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:554:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:489:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
2) headless chrome test
"after each" hook for "get-title-test":
TypeError: Cannot read property 'executeScript' of undefined
at Context.<anonymous> (test/headless-chrome-test.js:40:22)
3) headless firefox test
"before each" hook for "get-title-test":
WebDriverError: Misconfigured -- Sauce Labs Authentication Error.
You used username 'dbsweets' and access key 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXe399738f' to authenticate, which are not valid Sauce Labs credentials.
The following desired capabilities were received:
{'browserName': 'firefox',
'browserVersion': 'latest',
'platformName': 'linux',
'sauce:options': {'accessKey': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXe399738f',
'build': 'Sample Headless Tests',
'idleTimeout': 1000,
'maxDuration': 3600,
'name': 'headless-firefox-test-js',
'seleniumVersion': '3.141.59',
'tags': ['sauceDemo',
'async',
'node',
'webdriverjs',
'headless'],
'username': 'dbsweets'}}
at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:554:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:489:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
4) headless firefox test
"after each" hook for "get-title-test":
TypeError: Cannot read property 'executeScript' of undefined
at Context.<anonymous> (test/headless-firefox-test.js:39:22)
error Command failed with exit code 4.
sist output:
uname
: Darwin
echo $SHELL
: /bin/zsh
echo $TERM
: xterm-256color-italic
echo $TERM_PROGRAM
: iTerm.app
npm -v
: 6.10.3
node --version
: v10.15.3
There is no indication that my tests are failing on the Sauce Labs dashboard:
I assumed that the script was unable to find my username/access key because I did not provide it directly to the second and third tests. Unfortunately, even when invoking mocha directly, it is unable to find my credentials:
SAUCE_USERNAME=USERNAME-HERE SAUCE_ACCESS_KEY=ACCESS-KEY-HERE yarn mocha test/headless-chrome-test.js
All of the following links are broken in the README.md:
In order to run these scripts you must complete the following prerequisite steps:
Install Git
Install NPM/Node
Install a Framework
(Optional) Install an IDE
You can see it?
What script is doing what? The test.visual.sauce
is referring to the shared one, the test.visual.crossplatform
to the cross platform.
My advice would be (see also the best practices folder):
Originally posted by @wswebcreation in #148 (comment)
Change the folder structure
|_appium-examples
| (REMOVE and make new examples in `webdriverio/appium-web/best-practices|examples`-folder)
|
|_biometric-login
| (MOVE into `webdriverio/appium-app/examples/biometric-login`-folder)
|
|_headless-examples
| (REMOVE and make new examples in `webdriverio/webdriver/examples/headless`-folder)
|
|_image-injection
| (MOVE into `webdriverio/appium-app/examples/image-injection`-folder)
|
|_nightwatch (RESTRUCTURED)
| |_appium-web
| | |_examples
| | |_update-sauce-real-devices
| | |_README.md
| |_webdriver
| |_examples
| |_update-sauce
| |_README.md
|
|_on-boarding-modules (REMOVE)
|
|_protractor
| |_selenium
| |_best-practices
| |_README.md
|
|_puppeteer
| |_README.md
|
|_screener-runner (DEMO PROJECT DEPRECATED)
| |_README.md
|
|_testcafe
| |_best-practices
| |_README.md
|
|_testrunner-toolkit
| |_cypress
| | |_README.md
| |_playwright
| | |_README.md
| |_puppeteer
| | |_README.md
| |_testcafe
| |_README.md
|
|_up-download-file/appium
| (MOVE to `webdriverio/appium-app/examples/up-download-file`-folder)
|
|_visual-e2e
| |_examples
| |_README.md
|
|_w3c-example (REMOVE)
|
|_webdriverio
| (REFACTOR FOLDERS AND ADD NEW)
|
|_appium-app
| |_best practices (TODO)
| |_examples
| |_biometric-login (WAS MOVED)
| | |_README.md
| |_hybrid-app (TODO)
| |_image-injection (WAS MOVED)
| | |_README.md
| |_gestures (WAS MOVED)
| | |_README.md
| |_up-download-file (WAS MOVED)
| |_README.md
|_appium-web
| |_best practices (COPY FROM BEST PRACTICES FOR WEBDRIVER)
| | |_README.md
| |_examples
| |_dynamic-allocation (WAS MOVED)
| | |_README.md
| |_w3c
| |_README.md
|_webdriver
| |_best practices
| | |_README.md
| |_examples
| |_extended-debugging
| | |_README.md
| |_headless (MOVED FROM headless-examples AND ADJUSTED TO WEBDRIVERIO)
| | |_README.md
| |_performance
| | |_README.md
| |_sc
| | |_README.md
| |_up-download (NEW)
| |_README.md
|_README.md
Hi @wswebcreation -- Could you or Titus create a new release with the tag docs-1.1
please? The biometrics samples have been updated and I would like to reference them in the docs. Thanks!
README and/ or comment inside code should include description for user to change server region according to user account
The following error appears when trying to use the wrong region:
UnhandledPromiseRejectionWarning: WebDriverError: Uh oh, you've run out of minutes!
Please visit https://saucelabs.com/pricing to purchase a subscription.
Change line 35 to a different region than your account
Default server:
.usingServer('https://ondemand.saucelabs.com:443/wd/hub')
European server:
.usingServer('https://ondemand.eu-central-1.saucelabs.com:443/wd/hub')
#37 is connected to this issue
This issue only appears when using mocha, jasmine persist with the same error as described in the Issue 37
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.