Skip to content

A repository containing all C# examples for Sauce

Notifications You must be signed in to change notification settings

rajababuk/demo-csharp

 
 

Repository files navigation

C# Sauce Labs Demo Scripts and Frameworks

Codacy Badge Build Status

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.

Solution Outline

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

Setting Up a Selenium Project in Visual Studio

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.

Installing Visual Studio Community Edition

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.

  1. Go to the  Visual Studio download s page.

  2. Download the Community version.

  3. Decide if you want to take the survey or not.

  4. Click Yes to allow the app to make changes to your device.

  5. Click Continu e to accept the license terms.

  6. Select .NET desktop development, then click Install.

  7. Click Launch.

  8. Decide if you want to sign in with your Microsoft account, create an account, or sign in later.

  9. Select a color scheme, then click Start Visual Studio.
    Visual Studio opens.

Creating a Test Project

In this step you create a basic test project.

  1. In VS, select File > Project > Unit Test Project.

  2. In the Name field, name the project, then click OK.
    Visual Studio creates the project.

Adding the NuGet Packages

In this step, you add the NuGet packages you need to run your automated web tests on Sauce Labs.

  1. In the Solution Explorer panel to the right of the Visual Studio frame, right-click References.

  2. Select Manage  NuGet Packages.
    The NuGet window opens.

  3. In the Search field, enter Selenium Support.
    A list of Selenium packages appears.

  4. Select Selenium Support, then click Install.

  5. When the Preview Changes dialog box opens, click OK.
    The package is installed.

  6. Search for Selenium.WebDriver.ChromeDriver. Follow the same steps to install it.

  7. Search for NUnit and install it.

  8. Search for NUnit 3 Test Adapter and install it.

  9. Search for DotNetSeleniumExtras.WaitHelpers and install it.

  10. 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.

  11. Close the NuGet window.

Adding the Test Script

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. 

  1. Download the test script from Instant Sauce Test

  2. Delete the text in the VS file you created and paste in the script you downloaded.

  3. Save the file.

Getting Your Access Code on Sauce Labs

Before you can run your test on Sauce Labs, you need your user name and access key.

  1. 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.

  2. Click your name in the Account Profile menu in the upper-right corner.

  3. Click User Settings.

  4. Scroll down to Access Key and click Show.

  5. Click the Copy icon.

Updating Your Test Script

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.

Running Your Script on Sauce Labs

You’re now ready to run your test on Sauce Labs!

  1. In VS, click Test, point to Windows and click Test Explorer.

  2. In the Test Explorer panel, select your test and click Run All.
    You'll see that the test starts running.

  3. Log in to the Sauce Labs web interface and click Automated Tests.

  4. You'll see that the test ShouldOpenOnSafari is running.

  5. To see the details of the test when it completes, click ShouldOpenOnSafari

  6. You'll see that Test Success is selected. 

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

  8. 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. 

About

A repository containing all C# examples for Sauce

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 87.7%
  • HTML 7.5%
  • PowerShell 2.8%
  • Gherkin 1.4%
  • Other 0.6%