The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tabs Container
idSeleniumContainer
titleSeleniumContainer
directionhorizontal

Test Frameworks

Tabs Page
titleJava Examples
Tabs Container
idJava Examples Container
directionvertical
Tabs Page
titleTestNG
Expand
titleClick here to see the full example.

View Git file
pathheadless/src/test/java/SampleHeadlessSauceTest.java
repository-id33
branchrefs/remotes/origin/master

TestNG Example Walkthrough

  1. Download or clone the sample script from GitHub.

  2. Ensure you have the prerequisite software.

  3. Resolve dependencies with Maven:

    Code Block
    $ mvn dependency:resolve
  4. Export your Sauce Labs Username and Access Key:

    Code Block
    export SAUCE_USERNAME=my-sauce-username
    export SAUCE_ACCESS_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx2cy8f4
  5. Run the following command:

    Code Block
    $ cd headless/
    $ mvn clean test -Dtest=SampleHeadlessSauceTest

    You should see the following output (or something similar) in the console:

    Code Block
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running SampleHeadlessSauceTest
    Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@1ff8b8f
    May 31, 2019 11:46:23 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    title of page is: Swag Labs
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 15.082 sec
     
    Results :
     
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
     
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  17.308 s
Tabs Page
titlePython Examples
Tabs Container
idPython Examples Container
directionvertical
Tabs Page
titlePyTest
Expand
titleClick here to see the full example.

View Git file
pathheadless-examples/test_demo.py
repository-id36
languagepy
branchrefs/remotes/origin/master

Pytest Example Walkthrough

  1. Download or clone the sample script from GitHub.

  2. Ensure you have the prerequisite software.

  3. Install the following modules:

    Code Block
    pip install pytest pytest-xdist
  4. Export your Sauce Labs Username and Access Key:

    Code Block
    export SAUCE_USERNAME=my-sauce-username
    export SAUCE_ACCESS_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx2cy8f4
  5. Run the following command:

    Code Block
    pytest -n8 test_demo.py

    You should see the following output (or something similar) in the console:

    Code Block
    platform darwin -- Python 3.7.1, pytest-4.4.0, py-1.7.0, pluggy-0.12.0
    rootdir: /path/to/python/headless-examples
    plugins: forked-1.0.2, xdist-1.28.0
    gw0 [4] / gw1 [4] / gw2 [4] / gw3 [4] / gw4 [4] / gw5 [4] / gw6 [4] / gw7 [4]
    ....                                                                    
Tabs Page
titleNodeJS Examples
Tabs Container
directionvertical
Tabs Page
titleWebdriverIO
Expand
titleClick here to see the full example.

View Git file
pathwebdriverio/webdriver/examples/headless/test/configs/wdio.saucelabs.conf.js
repository-id38
languagejs
branchrefs/remotes/origin/master

WebdriverIO Example Walkthrough

  1. Download or clone the sample script from GitHub.

  2. Ensure you have the prerequisite software.

  3. Navigate to the headless-examples directory and install node package dependencies:

    Code Block
    $ cd headless-examples/
    $ npm install
  4. Export your Sauce Labs Username and Access Key:

    Code Block
    export SAUCE_USERNAME=my-sauce-username
    export SAUCE_ACCESS_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx2cy8f4
  5. Run the following command:

    Code Block
    $ npm test test/headless-chrome-test.js

    You should see the following output (or something similar) in the console:

    Code Block
     mocha "test/headless-chrome-test.js"
    
    
    
      headless chrome test
    Page Title is: Swag Labs
        ✓ get-title-test (2594ms)
    
    
      1 passing (13s)                                                              


Tabs Page
titleRuby Examples
Tabs Container
directionvertical
Tabs Page
titleRspec
Expand
titleClick here to see the full example.

View Git file
pathselenium-examples/rspec/spec/spec_helper.rb
repository-id37
languageruby
branchrefs/remotes/origin/master

More examples at Sauce Labs Training on GitHub: Ruby examples.

Rspec Example Walkthrough

  1. Setup Gemfile.

    • Install bundler so that we can easily update and resolve dependencies:

      Code Block
      $ gem install bundler
      
      
  2. Execute the bundle Command.

    • Use the following to install the required gems:

      Code Block
      $ bundle install --path .bundle
  3. Run the Test Scripts.

Tabs Page
titleC# Examples
Tabs Container
directionvertical
Tabs Page
titleNUnit
Expand
titleClick here to see the full example.

View Git file
pathSauceExamples/SeleniumNunit/SimpleExamples/SimpleHeadlessTest.cs
repository-id34
languagec#
branchrefs/remotes/origin/master

NUnit Example Walkthrough

Refer to the instructions at Sauce Labs Training on GitHub: C# demo scripts.

Data Center Endpoints for Sauce Headless

...