Endtest

Endtest

›Web Tests

Web Tests

  • How to create Web Tests
  • Finding elements in Web Applications
  • How to execute Web Tests
  • Assertions for Web Tests
  • IF Statements for Web Tests
  • Web Applications with restricted access
  • How to test in iframes
  • How to test in multiple tabs
  • How to test File Uploads
  • How to test File Downloads
  • How to test Emails
  • How to test PDF files
  • How to test Chrome Extensions
  • Dealing with reCAPTCHA
  • Dealing with Dynamic Locators
  • Dealing with Canvas Elements
  • Performing a Drag and Drop
  • Execute JavaScript
  • Testing WebRTC Applications
  • How to scroll in Web Tests
  • How to test Checkboxes
  • How to test Dropdowns
  • Dealing with Sessions
  • Web Crawler
  • Export Web Tests
  • Migrating from Selenium

Mobile Tests

  • How to create Mobile Tests
  • Finding elements in Mobile Applications
  • How to execute Mobile Tests
  • Assertions for Mobile Tests
  • IF Statements for Mobile Tests
  • How to scroll in Mobile Tests
  • Performing Complex Gestures

Advanced

  • Variables
  • Waits
  • Endtest API
  • Scheduler
  • Drive
  • Adding Collaborators
  • Computer Vision
  • Importing Test Cases
  • Using Loops
  • Data-driven Testing
  • Send API Requests
  • Read SMS
  • Execute SQL queries
  • Self-Healing Tests
  • Email Notifications
  • Slack Notifications
  • PagerDuty Notifications
  • Webhook Notifications
  • Automatic Backup
  • Advanced Settings
  • Multiple environments
  • How to stop a test
  • Utilities
  • Utilities API
  • Team
  • On-Premises

Integrations

  • Atlassian Jira
  • Slack
  • PagerDuty
  • Microsoft Teams
  • Mattermost
  • Jenkins
  • GitHub
  • Azure DevOps
  • GitLab
  • TeamCity
  • CircleCI
  • TravisCI
  • Bitbucket
  • Heroku
  • Bamboo Server
  • Test Case Management
  • SSO
  • BrowserStack
  • Sauce Labs

Execute JavaScript

Introduction

There are certain scenarios where you might need to execute some JavaScript code.

For example, let's say you want to generate a complex random pattern that you cannot obtain by using our Set Variable action and by concatenating variables and strings.

You can execute JavaScript code in your Web Tests by using an Execute JavaScript step.

The JavaScript variables and the Endtest variables are on different layers, but you can exchange values between them.

You can transfer a value from a JavaScript variable to an Endtest variable by using the Extract Value from JS variable option from the Set Variable action.

And you can also transfer a value from an Endtest variable to a JavaScript variable by using the Transfer to JavaScript action.

You can find more details about the Set Variable action and variable concatenation in the Variables chapter.

Steps

  1. Add an Execute JavaScript step.
  2. Write your JavaScript code in our JavaScript editor.
  3. Save the test.
  4. Execute the test.

Mandatory Guidelines

  1. Do not use the var,let or const keywords when declaring variables and constants in your JavaScript code.
  2. Do not add comments in your JavaScript code.
  3. Test your JavaScript code in your own browser console to make sure that it works as expected.
  4. Avoid using the Execute JavaScript action to click on elements or to write text in inputs.
    Using JavaScript to perform such actions does not mimic a real user and your web application might behave differently.
  5. The JavaScript code is executed by the specific webdriver for each browser.
    This means that it might not behave in the same way in all browsers and you might need to adapt it.
    For example, if you want your JavaScript code to run correctly in Firefox, you must use window. before each variable.
  6. If the execution of the JavaScript will throw any errors, you will see them in the output of that step.



External JavaScript Libraries

You can also import an external JavaScript library in an Execute JavaScript step.

For example, this is how you would import the Chance.js library:

s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://chancejs.com/chance.min.js";
document.getElementsByTagName("head")[0].appendChild(s);

And this is how you would call the phone() method from that library:

phone = chance.phone();

The methods from the imported JavaScript library cannot be called from the same Execute JavaScript step.

A new Execute JavaScript step should be added for that.

As mentioned at the beginning of this chapter, you can transfer a value from a JavaScript variable to an Endtest variable by using a Transfer to JavaScript step.

← Performing a Drag and DropTesting WebRTC Applications →
  • Introduction
  • Steps
  • Mandatory Guidelines
  • External JavaScript Libraries
© Endtest Inc.