Menu

Automated Script Generator

The automated script generator is a popular feature used by teams accelerating their move to test automation from exploratory and manual test cases.  Teams can use Desktop and Web Explorer to automatically generate web automation test scripts after their session has completed. 

Automate with Web Explorer

After installing Web Explorer, you can start a new recording session on its supported browser. The below screenshot shows the Start Session screen from Web Explorer for Google Chrome. 

Automate with Desktop Explorer

After installing Integrated Desktop Explorer, ONLY select Google Chome to create an automated test script.  

Note: If you select additional applications, the automated script will not work. 

Generate Automated Test Script 

When the recording is completed you will be navigated to qTest Sessions Module editor to review the recorded test session data.

In order to generate automated script for a web session, click on the Generate Script button 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
    • Python Selenium: generate script in Python 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:
    1. Package Name: select a name for the package, the default value is com.companyname.tests 
    2. Class Name: Enter class name of the generated test case, default value is TestCase1
    3. Web Driver Path: specify web driver path for the script to run, the 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
    4. Clear text field before sending key: select this option to generate addition script to clear text in input field before sending an actual text to that field. This field is selected by default.
    5. Always execute an action in the latest window: when this option is selected, every action will be executed in the last opening browser window. This option is selected by default.
    6. 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: 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: 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.

Subscribe To Our Blog
Powered by Zendesk