siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
164 lines (100 loc) • 7.15 kB
Markdown
{/logo@2x.png}
Integration with Sauce Labs cloud-testing infrastructure
==========================================================
Most of the web projects supports all major browsers. When aiming for the full certainty, about the quality of the product in every supported browser,
a logical step is to run the test suite in all those browsers. Counting Chrome, Firefox, Safari, Edge - thats at least 4x
of the single test suite launch, so for the single-machine setup, the workload can quickly become extremely intense.
One way to solve this bottleneck is to maintain a farm of virtual machines with various OS/browser combinations.
This can be tricky and will consume lots of your time and resources. Another, more elegant way is to use services
providing the same infrastructure in the cloud. Thanks to services such as [Sauce Labs](http://www.saucelabs.com/) it is now very simple.
Authentication
--------------
When registering an account in Sauce Labs, you will receive a user name (displayed in the right top corner after logging in) and an api key
(can be found in the left-bottom corner of the "Account" page).
Later in this guide we will refer to these as "Sauce Labs username" and "Sauce Labs access key" (or Sauce Labs API key).
Quick testing
-------
Assuming your local web server is configured to listen at host "localhost" on port 80, all you need to launch your test suite in the cloud
is to sign up for the SauceLabs trial and run the following command:
__SIESTA_DIR__/bin/webdriver http://localhost/my/siesta/project/wrapper.html --saucelabs SL_USERNAME,SL_KEY
--cap browserName=firefox --cap platform=windows
That's all, the only difference from a normal Siesta automated launch, is the `--saucelabs` option, which is a shortcut performing
a few additional actions. We'll examine what happens under the hood later in this guide.
Note how we have specified the desired OS/browser combination using the `--cap` switch (it specifies remote webdriver capability).
For a full list of supported capabilities please refer to <https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities>.
If your webserver listens on a different host (`mylocalhost` for example) then the `--saucelabs` option should look like:
--saucelabs SL_USERNAME,SL_KEY,mylocalhost
Finding the values for `platform` and `browserName` capability
---------------------------
Sometimes it can be tricky to find the value for the "platform" platform, Selenium documentation provides only the generic ones.
The best way to do it is to start manual testing session, choosing the desired OS / browser combination from the SauceLabs UI.
Then you can immediately terminate the session, and open the page with session information in the SauceLabs dashboard (check the "Manual
sessions" tab).
There, on the "Metadata" tab, you can find the "Base config" property, which contains WebDriver capabilities for the OS/Browser
you've chosen.
Parallelization
---------------
When using cloud-based infrastructure, each test page is running inside of the own VM, which guarantees the exclusive focus owning
and allows us to run several test pages in parallel. Naturally, that speed ups the test execution, by the number of parallel sessions
we can run.
This can be done using the `--max-workers` option, that specifies the maximum number of parallel sessions.
Under the hood
-------------
Let's examine what happens under the hood when we use the `--saucelabs` shortcut option. In fact, we don't have to use this shortcut
option and can perform all the steps listed below manually.
1) The first thing that happens is that Siesta establishes a local tunnel from your machine to the SauceLabs server, using the SauceLabs binaries.
You can do this step manually by using the batch file in the Siesta package:
__SIESTA_DIR__/bin/sc -u SL_USERNAME -k SL_API_KEY -t mylocalhost
When launched successfully, you should see the following text:
11 Aug 13:21:22 - Sauce Connect 4.3, build 1283 399e76d
11 Aug 13:21:22 - Using CA certificate bundle /etc/ssl/certs/ca-certificates.crt.
.....
11 Aug 13:22:12 - Starting Selenium listener...
11 Aug 13:22:15 - Sauce Connect is up, you may start your tests.
11 Aug 13:22:15 - Connection established.
2) The `--host` option is set to point to the SauceLabs server, based on your username and access key:
--host="http://SL_USERNAME:SL_API_KEY@ondemand.saucelabs.com:80/wd/hub"
To sum up, instead of using the `--saucelabs` shortcut option, we could:
- launch the tunnel manually:
__SIESTA_DIR__/bin/sc -u SL_USERNAME -k SL_API_KEY -t mylocalhost
- specify the command as:
__SIESTA_DIR__/bin/webdriver http://localhost/my/siesta/project/wrapper.html
--host="http://SL_USERNAME:SL_API_KEY@ondemand.saucelabs.com:80/wd/hub"
--cap browserName=firefox --cap platform=XP
For convenience, instead of setting the `--host` option manually, one can specify `--saucelabs-user` and `--saucelabs-key` options.
__SIESTA_DIR__/bin/webdriver http://localhost/my/siesta/project/wrapper.html
--saucelabs-user=SL_USERNAME --saucelabs-key=SL_API_KEY
--cap browserName=firefox --cap platform=XP
Shared tunnel
---------
We found, that if you and some other team member has manually started unnamed SauceConnect tunnels, tests can't find which tunnel
to use and can't open project page. This can be solved by starting the tunnel with the `--tunnel-identifier` option, and
then specifying that id with the Siesta's `--saucelabs-tunnel-identifier` option.
To share the tunnel to BrowserStack between the tests launches (saves the tunnel up/down time, convenient during development), use the
`--saucelabs_` option, which does the same things as `--saucelabs` but uses existing tunnel.
Then you'll need to launch the tunnel manually:
__SIESTA_DIR__/bin/sc -u SL_USERNAME -k SL_API_KEY -t mylocalhost
Conclusion
----------
As you can see, thanks to the excellent [Sauce Labs](http://www.saucelabs.com) infrastructure, launching your tests in the cloud is as easy as specifying
one extra argument on the command line. The benefits of cloud testing are obvious - no need to waste time and resources setting up and maintaining your own VM farm,
and additionally you can run your test suite in various browsers in parallel.
See also:
---------
<https://docs.saucelabs.com/reference/sauce-connect/>
Buy this product
---------
Visit our store: <https://bryntum.com/store/siesta>
Support
---------
Ask a question in our community forum: <https://www.bryntum.com/forum/viewforum.php?f=20>
Subscribers can post expedited questions in Premium Forum: <https://www.bryntum.com/forum/viewforum.php?f=21>
Please report any bugs through the web interface at <https://www.assembla.com/spaces/bryntum/support/tickets>
See also
---------
Siesta web-page: <https://bryntum.com/products/siesta>
Other Bryntum products: <https://bryntum.com/products>
COPYRIGHT AND LICENSE
---------
Copyright (c) 2009-2022, Bryntum AB & Nickolay Platonov
All rights reserved.
images