18. Generating Automated Script

From qTest 8.1, you can generate automated script from session recorded by qTest Explorer applications and execute the script against Selenium or Protractor frameworks. What you need is qTest 8.1+ and supported eXplorer versions installed on your browser.

Instructions

This instruction shows how to use script generation feature by

  • installing qTest Explorer applications
  • using Web Explorer or Desktop Explorer to record a web session
  • generating automated script from the recorded web session
  • executing the generated script against Selenium framework
  • executing the generated script against Protractor framework

Install Explorer application

To install Explorer applications that supports recording web session and use the recorded session data to generate automated script, go to this download page and download your prefered edition:

  • qTest Web Explorer Extension for Chrome, version 1.1.14 or later
  • qTest Web Explorer Extension for Safari, version 1.1.12 or later
  • Integrated Desktop Explorer, version 6.9.1.3 or later

Record web session using qTest Web Explorer 

After installing qTest Web Explorer, you can start a new recording session on its supported browser. Below screenshot show the Start Session screen from Web Explorer for Chrome

 

Record web session using Integrated Desktop Explorer 

After installing Integrated Desktop Explorer, you can start a new recording session against Chrome browser (and only Chrome application at a time).

When the recording is completed you will be navigated to qTest Session Editor to review the recorded session data.

In order to generate automated script for a web session recorded by qTest Web (or Integrated) Explorer from Session editor, click on the generate script icon in editor toolbar, as below:

 You will be presented with a Script generator dialog, as below:

Next, follow below steps to generate automated script:

  • Select screen option in Screen list to narrow down the actions to be generated. By default, the selected value is 'All screens' which means all the actions of all captured screens will be used to generate script
  • Select a script generator from Plugin list:
    • Java Selenium: generate script in Java language that can be executed against Selenium framework
    • C# Selenium: generate script in C# language that can be executed against Selenium framework
    • Protractor: generate script in JavaScript language that can be executed against Protractor framework
  • Configure settings for the selected plugin by click on the gear icon next to the plugin list. For example, if your selected plugin is Java Selenium, you will be presented with default settings for this plugin as shown in below screenshot:

  • Below is the description of Java Selenium settings:
    • Package Name: select a name for the package, default value is com.companyname.tests 
    • Class Name: Enter class name of the generated test case, default value is TestCase1
    • Web Driver Path: specify web driver path for the script to run, default value is empty. If you do not enter a value for this field, you will need to enter it in the resulting generated script before executing it
    • Clear text field before sending key: select this option to generate addition script to clear text in input field before sending actual text to that field. This field is selected by default.
    • Always execute action in latest window: when this option is selected, every action will be executed in the last openning browser window. This option is selected by default.
    • Generate action description as code comment: like the name implied, selecting this option will generate action description as code comment for every script action. This option is not selected by default

Example 1: Generate automated script with built-in Java Selenium plugin

From Script Generator screen, input following data:

  • Screen: All screens
  • Plugin: Java Selenium
  • Settings:
    • Package Name: com.qas.selenium.tests 
    • Class Name: Enter class name of the generated test case, default value is ProductsPageTestCase
    • Web Driver Path: C:\webdriver\webdriver.exe
    • Clear text field before sending key: checked
    • Always execute action in latest window: checked
    • Generate action description as code commentchecked
  • The generated script will look like below:

Next, do the following to generate automated script:

  • Exclude specific step(s) to not generate script for it in the left panel by unchecking the checkbox associated with it
  • With each selected step, you can also choose one of the selectors behind it which, when being generated to script, will be used by Selenium to locate the UI element when the script is executed
  • Copy the generated script to clipboard by clicking on Copy to Clipboard button
  • Download the generated script and save it as a text file by clicking on Download button
  • or close the Script Generator dialog using Close button

Assume you chose to download the generated script as save it as ProductsPageTestCase.java. Next step is to use that script in your automation project. Below is the screenshot showing a Selenium project in Eclipse IDE including the downloaded ProductsPageTestCase.java

Tip: follow this article http://toolsqa.com/selenium-webdriver/configure-eclipse-with-selenium-webdriver/ to learn how to setup Selenium automation project in Eclipse

To execute the script, right click on ProductsPageTestCase.java in the Package Explorer and choose Run As > JUnit Test, as below screenshot

Example 2: Generate automated script with built-in Protractor plugin

From Script generator screen, enter following data:

  • Screen: All screens
  • Plugin: Protractor
  • Settings:
    • Clear text field before sending key: checked
    • Always execute action in latest window: checked
    • Generate action description as code comment: keep it unhecked
  • The generated script will look like below:

Next, you can do the following to generate automated script:

  • Exclude specific step(s) to not generate script for it in the left panel by unchecking the checkbox associated with it
  • With each selectedstep, you can also choose one of the selectors in the bottom left which, when being generated to script, will be used by Protractor to locate the UI element when the script is executed
  • Copy the generated script to clipboard by clicking on Copy to Clipboard button
  • Download the generated script and save it as a text file by clicking on Download button
  • or close the Script Generator using Close button

Assume you chose to download the generated script as save it as TestCase1.js (in Protractor this file is called a spec). Next step is to follow the instruction on Protractor website at http://www.protractortest.org/ to learn how to execute the script yourself.