This directory contains example scripts and dependencies for running automated Selenium tests on Sauce Labs using C#. You can use these scripts to test your Sauce Labs authentication credentials, the setup of your automated testing environment, and try out Sauce Labs features, like cross-browser testing. Feel free to copy these files or clone the entire directory to your local environment to experiment with creating your own automated Selenium tests!
For Demonstration Purposes Only
The code in these scripts is provided on an "AS-IS” basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.
If you are looking for tests that can help you quickly and easily get started with Sauce Labs, those are here: https://github.com/saucelabs-training/demo-csharp/tree/master/SauceExamples/Web.Tests/OnboardingTests
If you are looking for advanced tests that use test automation best practices on Sauce Labs, those are here: https://github.com/saucelabs-training/demo-csharp/tree/master/SauceExamples/Web.Tests/BestPractices
If you are looking for W3C examples using Sauce Labs: https://github.com/saucelabs-training/demo-csharp/blob/master/SauceExamples/SeleniumNunit/SimpleExamples/Selenium4.cs
Examples of tests using MsTest are here: https://github.com/saucelabs-training/demo-csharp/tree/master/SauceExamples/SeleniumMsTest
This procedure shows you how to set up a Selenium project in Visual Studio (VS). Once you set up a project, you'll run a test script written in C#, which we provide, on Sauce Labs. In the future, you can use this script as a template for your own automated tests.
In this step you download and install Visual Studio Community, the free version of Visual Studio. If you already have it installed, go to the next step, Creating a Test Project.
-
Go to the Visual Studio download s page.
-
Download the Community version.
-
Decide if you want to take the survey or not.
-
Click Yes to allow the app to make changes to your device.
-
Click Continu e to accept the license terms.
-
Select .NET desktop development, then click Install.
-
Click Launch.
-
Decide if you want to sign in with your Microsoft account, create an account, or sign in later.
-
Select a color scheme, then click Start Visual Studio.
Visual Studio opens.
In this step you create a basic test project.
-
In VS, select File > Project > Unit Test Project.
-
In the Name field, name the project, then click OK.
Visual Studio creates the project.
In this step, you add the NuGet packages you need to run your automated web tests on Sauce Labs.
-
In the Solution Explorer panel to the right of the Visual Studio frame, right-click References.
-
Select Manage NuGet Packages.
The NuGet window opens. -
In the Search field, enter Selenium Support.
A list of Selenium packages appears. -
Select Selenium Support, then click Install.
-
When the Preview Changes dialog box opens, click OK.
The package is installed. -
Search for Selenium.WebDriver.ChromeDriver. Follow the same steps to install it.
-
Search for NUnit and install it.
-
Search for NUnit 3 Test Adapter and install it.
-
Search for DotNetSeleniumExtras.WaitHelpers and install it.
-
If you want to check that all the packages are installed, in Solution Explorer, click packages.config.
An XML page appears that shows all the installed packages. -
Close the NuGet window.
In this step, you download and run a C# test script from Sauce Labs. The script opens up the Sauce Labs sample web application (a simulated online store) and simulates a login with a sample user.
-
Download the test script from Instant Sauce Test
-
Delete the text in the VS file you created and paste in the script you downloaded.
-
Save the file.
Before you can run your test on Sauce Labs, you need your user name and access key.
-
Log in to Sauce Labs at www.saucelabs.com .
If you don’t have a Sauce Labs account you can create one and use Sauce Labs for free for two weeks. -
Click your name in the Account Profile menu in the upper-right corner.
-
Click User Settings.
-
Scroll down to Access Key and click Show.
-
Click the Copy icon.
You need to enter your Sauce Labs user name and access key into the test script. In VS, scroll down until you see:
Enter your own credentials inside the quotes. You should be able to paste in your access key.
You’re now ready to run your test on Sauce Labs!
-
In VS, click Test, point to Windows and click Test Explorer.
-
In the Test Explorer panel, select your test and click Run All.
You'll see that the test starts running. -
Log in to the Sauce Labs web interface and click Automated Tests.
-
You'll see that the test ShouldOpenOnSafari is running.
-
To see the details of the test when it completes, click ShouldOpenOnSafari.
-
You'll see that Test Success is selected.
-
Click the Play button.
You'll see a video of the entire test run. The test opens up the Sauce Labs sample application. It then logs in to the application and clicks the LogIn button. -
Go back to VS.
In the Test Explorer pane, you'll see a green check mark next to your test, which means the test completed successfully. You can also click the Output tab to see some details.
Congratulations, you've just run your first test on Sauce Labs! Now try using our Platform Configurator to change the desired capabilities of your test to run it on different combinations of platform, operating system, and browser.