Menu

Selenium Automation

Overview

This example illustrates how to use the Shell Script Automation Host Feature to build a .csproj with msbuild, run nunit tests with nunit3-console runner and automatically upload the test results to qTest Manager.

Currently, this example illustrates how to run the script on Windows, but a .sh file is included for Mac users to configure.

Prerequisites

You will need to install the following applications to use the TestNG with Maven Build Automation Feature:

Tips for Prerequisite Set Up

Check PIP Installation

These instructions are for Command Prompt (Windows.):

  1. Run this command to ensure the PIP install with Python was successful. It should output the pip version:
    pip --version
    Note: pip3 will work as well, example: pip3--version

  2. If PIP did not install, run the command below:
    python -m -ensurepip --default-pip
    Note: For more information on PIP installation, read here: https://packaging.python.org/tutorials/installing-packages/
  3. Once the PIP install is successful, run the following commands individually:
    pip install requests
    pip install urllib3
    pip install beautifulsoup4
    pip install lxml
    pip install pybase64

Note: If using pip3, run the commands with pip3 in the individual install commands listed above. Example: pip3 install requests
These commands will install the necessary modules required to run the python scripts. The modules are used to send requests to the API, read json configuration files,  parse xml documents, and upload files to qTest.

Windows

Ensure that all environment variables are set up correctly, before running the automation host script; specifically, that the PATH variable is updated for Python, nunit3-console, and MSBuild.

Selenium Automation Host Example from GitHub

https://github.com/sanjayjohn/shell-agent-samples/tree/master/AutomationHostExamples/automateSelenium

Update Configuration File

Open the conf.json file and update with your personal information. Enter your own qTest URL and API Token found in your qTest Manager Environment.

  • git_url: The shell script uses the URL to clone a repository and send pull requests everytime it runs if -git input is used.
  • local_repository: The folder containing the Selenium C Sharp. The shell script will use this to know where to run the nunit test. To run the nunit tests, the shell script looks for .dll file located in bin/Debug. Make sure the local repository folder name is the same as the .dll file that will create when the project gets built. 
  • qtest_api_token: The token used to authorize the connection to qTest Manager.
  • qtest_url: The personal URL that is used to access QASymphony API.
    git_config.png

For this example, we will be NOT be using a GitHub sample, but instead the Selenium C Sharp project which is located in the repository, as documented in the conf.json sample file below. For the git URL and local repository use the information shown below in the example configuration file. Make sure to use your own API Token and URL, or the demo will not work.
seleniumconf.png

Setup Automation

  1. Navigate to your Automation Host.
    image3.png

  2. Select the 'Add' button to add a new agent.
  3. In the New Agent window, enter the appropriate information for the following fields:
    seleniumwindowshost.png
    • General Agent Information
      • Agent Name: Name

      • qTest Manager Project: Select your project

      • Agent Type: Choose Shell Agent

    • Test Scripts Information

      • Directory: The directory containing your scripts and shell agent (Directory where the scripts clone.)

      • Allocated Execution Time: Amount of time you expect the script to take to execute in minutes.

      • Kick-off Scripts: The file path to your shell script. This shell script takes in two inputs, one for using git and the second for updating your current test cycle.

        • To give the shell script permission to run, use the following command:
          Windows: run.bat
          Linux: chmod +x run.sh
        • Shell Script Inputs:

          • -g
            Uses GitHub to clone a test case repository, and send pull requests every time the shell script runs.

          • -u 
            Updates an existing test cycle or create a new test cycle if the first test run.
            (To create a new test cycle every time the script runs, do not use this argument.)

          • -b
            <'branch name'> If the Github parameter is used, this input allows the user to clone the repository and make a branch that they specify with the input. An example of using -b is shown in automateJunit.

            Important: To run the shell agent, without using GitHub or updating the existing test cycle, do not include the parameters above in the Kick-off Scripts section.

  4. Save to close.

Run the Shell Script

To start the shell script, select the yellow button in the action field which will upload all of the test cases to qTest Manager.  
yellowbuttonimg.png

Schedule your Tests

  1. In Manager, select the Test Execution tab. 
  2. Locate the Test Cycle in your project named "Selenium Automated Tests."
    seleniumcycle.png
  3. Select the Test Cycle, and it will display all of the tests that had been run through the Robot build along with their statuses.
    seleniumtests.png

  4. Click the checkboxes for the specific tests you would like to schedule and select 'Schedule' from the 'More' drop-down menu.
    seleniumschedule.png

  5. In the Agent drop-down menu, select the Shell Agent and Click OK.
    seleniumchoosehost.png

  6. Once the tests are scheduled, you will need to go back to the Automation Host and select Poll Now to kick the Shell Agent off.
    image7.png

 

Important: The shell script will only run the scheduled tests and upload those results to qTest Manager.

Tips for Nunit Parser

The Nunit parser reads from TestResult.xml file, which is located in the bin/Debug directory. Ensure that the .dll file is located in this directory before running the shell script. Also, make sure the name of the directory where the project is located has the same name as the .csproj being built.

In the example shown below, "SeleniumDemoProject" is the name of the local directory, and it is the same name as the .csproj called "SeleniumDemoProject.csproj." 

seleniumfilename.png

Powered by Zendesk