Giter Site home page Giter Site logo

saucelabs-training / demo-js Goto Github PK

View Code? Open in Web Editor NEW
90.0 90.0 98.0 253.52 MB

A repository containing examples using NodeJS with Sauce Labs

License: MIT License

JavaScript 70.18% Dockerfile 0.01% Shell 0.72% Batchfile 0.02% Gherkin 0.30% TypeScript 28.77%

demo-js's People

Contributors

dependabot[bot] avatar dpgraham avatar eyaly avatar friggahel avatar johnorrsauce avatar joshmgrant avatar joventuraz avatar kafunk avatar kaochris avatar luisvelasquezsauce avatar nadvolod avatar tacktician avatar vrunoa avatar wswebcreation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

demo-js's Issues

Nightwatch custom sauce end: Session ID is undefined.

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:
e3b96067947456e1bc63472648a6183c

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();
  },
};

Failing 4/6 tests. Cannot read property executeScript of undefined

Bug Report

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.

My Local Versions

sist output:

shell

uname: Darwin
echo $SHELL: /bin/zsh
echo $TERM: xterm-256color-italic
echo $TERM_PROGRAM: iTerm.app

node

npm -v: 6.10.3
node --version: v10.15.3

Dashboard View

There is no indication that my tests are failing on the Sauce Labs dashboard:

image

Attempted Fixes

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

Problems using onboarding demo Module 1: Running your first test

Description

Cannot reproduce the steps provided on README

How to test / reproduce the issue

Follow README steps
Change line 18, removing x from describe

Screenshots

Following a gif demonstrating the results after trying to reproduce the exact steps, using npm test command

onboardin-testing

Following a gif demonstrating the results after trying to reproduce the steps but running npx instead of npm test

onboardin-npx-testing

Errors

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-safari

0 passing (73ms)
1 failing

  1. 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)
(Use node --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)

Create a 'best-practices' implementation in TS

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

saucelabs support for react unit testing

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 ?

Links broken

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

Change folder structure

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

Should include description for user to change server region according to user account

Description

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.

server2-low

How to test/ reproduce error

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')

Other observations

#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

Fix WDIO CI

I notice that you broke CI here, if it makes sense to fix it, maybe we should? I don't know or care about Nightwatch enough to do it myself haha.
Screen Shot 2020-07-14 at 3 51 17 PM

Update `test.visual.sauce` is referring to the shared one, the `test.visual.crossplatform` to the cross platform.

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):

  • have a shared one that only contains framework setup, not caps, no Sauce reference
  • have a sauce shared with only the sauce config extending the shared one
  • have separate config files that will be triggered with the scripts here and only extend the sauce.shared with different caps

Originally posted by @wswebcreation in #148 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.