LambdaTest Selenium Automation Grid is a cloud-based, scalable Selenium testing platform which enables you to run your automation scripts on 2000+ different browsers and operating systems. You can now run your JavaScript Selenium automated test cases on a scalable Selenium infrastructure that is running real browsers and real operating systems.
This post will help you in getting started with configuring and running your JavaScript-based automation test scripts on LambdaTest Selenium cloud platform using Protractor Selenium. This topic will help you to:
Before getting started with Automated Scripts using Selenium with Protractor test automation on LambdaTest, you need to:
1 |
npm install npm@latest -g |
Running Protractor Selenium test scripts on LambdaTest Selenium grid is as easy as changing a few lines of code. To start with, you would have to invoke Selenium remote webdriver instead of local browser webdriver. In addition, since we are using remote webdriver, we have to define which browser environment we want to run the test. We do that by passing browser environment details to LambdaTest Selenium grid via desired capabilities class. You can use LambdaTest Capabilities Generator to select & pass those browser environment specifications.
Let’s check a sample Protractor Selenium code running LambdaTest Selenium grid. This is a simple Protractor test automation script that tests a sample to-do list app. The code marks two list items as done, add a list item and then finally give the total number of pending items as output.
You can also find this code at our GitHub repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// spec.js describe('Add todo Lists', function () { browser.ignoreSynchronization = true; it('Add Customer Test', function () { browser.get('https://lambdatest.github.io/sample-todo-app/'); browser.driver.findElement(by.name('li1')).then(function (foundElement) { foundElement.click(); }); browser.driver.findElement(by.name('li2')).then(function (foundElement) { foundElement.click(); }); browser.driver.findElement(by.id('sampletodotext')).then(function (foundElement) { foundElement.clear(); foundElement.sendKeys("Yey, Let's add it to list"); }); browser.driver.findElement(by.id('addbutton')).then(function (foundElement) { foundElement.click(); }); var foo = element(by.xpath('//html/body/div/div/div/ul/li[6]/span')); expect(foo.getText()).toEqual("Yey, Let's add it to list"); browser.executeScript("lambda-status=passed"); browser.driver.quit(); }); }); |
Below is the export.config file where we will be declaring the desired capabilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
exports.config = { seleniumAddress: 'https://hub.lambdatest.com/wd/hub', // add more browsers to this array for more parallel tests!! multiCapabilities: [{ 'browserName': 'firefox', 'platform': 'WIN10', 'version':'62.0', }], //Add test scripts in this array to execute in parallel specs: ['tests/spec.js'] }; |
The Selenium Webdriver test would open a URL, mark the first two items in the list as done, add an item in the list, and return the total number of pending items. Your results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on LambdaTest dashboard. LambdaTest Dashboard will help you view all your text logs, screenshots and video recording for your entire Selenium tests.
You would need to execute the below command in your terminal/cmd.
1 |
protractor conf.js |
Protractor is an E2E(End-to-End) framework for testing an AngularJS application. Protractor test framework provides a sound evaluation of your web application by interacting with it just as an end user would, and executing tests through a real browser. It also offers Angular-specific strategies, so you could test Angular-specific elements without putting any extra effort from your end for the setup. Protractor is very convenient to use with continuous synchronization, the next steps in your test are automatically taken care of by the Protractor as soon as the pending tasks of the web page get completed. Protractor by default make use of Jasmine (Behavior-Driven JavaScript) test framework as the test interface.
If you are using Protractor test automation or planning to use Protractor selenium test automation, you can get started with LambdaTest Selenium grid quite easily. Integrating LambdaTest with Protractor will give your automation build capabilities to run on 2000+ different browsers, enabling you a wider test coverage. Coupled with Protractor’s inherent capabilities to manage tests, you get greater flexibility in running parallel test threads, boosting your build speed by multiple times.
In this post, we are going to dive into how you can integrate LambdaTest Selenium cloud grid in your Protractor Selenium testing suite. We are also going to touch upon how you can take advantage of LambdaTest parallel testing capabilities to speed up your test times and how you can leverage Lambda Tunnel feature to test your locally hosted or privately hosted pages even before launch.
As we said earlier the first step is to configure your test scripts to connect with LambdaTest Selenium automation gird. In the above mentioned JavaScript code, the first thing you would notice is the invoking of remote webdriver instead of the native browser webdrivers. So for example if you are planning to run on Firefox browser in your local machine, you would be using Firefox browser driver like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//In Conf.js exports.config = { seleniumAddress: 'https://hub.lambdatest.com/wd/hub', // add more browsers to this array for more parallel tests!! multiCapabilities: [{ 'browserName': 'firefox', 'platform': 'WIN10', 'version':'62.0', }], //Add test scripts in this array to execute in parallel specs: ['tests/spec.js'] }; <pre> <p> Since now you are performing the tests on LambdaTest's Firefox browser, the code has to be modified a bit. To run the code on Firefox on LambdaTest Firefox browser, you'd need to add the following command to your existing JavaScript code: </p> <pre> seleniumAddress: 'https://USERNAME:ACCESSKEY@hub.lambdatest.com/wd/hub' |
In the JavaScript code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object.
Our Capabilities Generator will automatically generate the program, based on your provided input. For Instance, if you select the below configurations:
Then Capabilities Generator at LambdaTest will provide you with the below program:
1 2 3 4 5 6 7 8 9 10 11 |
var capabilities = { "build" : "your build name", //You can edit this and assign a build name to your build "name" : "your test name", // Assign a name to your Test using this "platform" : "Windows 8.1", // The operating system on which you want to test your website "browserName" : "Firefox", // The browser on which you want to test "version" : "62.0", // The browser version which you've selected to perform the test upon "resolution" : "1280x1024", // The resolution in which you want to run the test as per your operating system "selenium_version" : "3.11.0", //The version of Selenium on which the test will run "visual" : true, "firefox.driver" : v0.21.0 } |
The most important capabilities to understand here are ‘browserName’, ‘versions’, and ‘platform’. They define which browser environment you wish to run the test on. Rest of the capabilities are important in test management and debugging. We have an inbuilt capabilities generator tool as well that you use to generate capabilities code for your test suite.
You can also checkout our documentation on capabilities generator to understand more about individual capabilities.
In addition to default Selenium Grid capabilities, LambdaTest also has platform specific capabilities like a video recording of test runs, console logs of each test run, network logs of each test run, custom profiles for specific browsers, etc. Do check out our documentation on LambdaTest Advanced capabilities as well.
LambdaTest allows you to test your locally hosted or privately hosted websites or web applications with the help of Secure Shell (SSH) Tunnel connection. Lambda Tunnel allows you to test your website or web-pages for cross browser compatibility even before they are live. You can connect your local server with LambdaTest’s Secure Cloud server using SSH tunnel and can perform cross browser testing on LambdaTest’s Selenium browser grid. You can also perform testing from different geo locations having different IP addresses and also test the applications secured with your organization’s firewall.
Follow our documentation on Lambda Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.
Download the binary file of:
Once you extract the file, you need to enter the following command in your command terminal. Make sure that you redirect the pointer to the same folder in which you’ve extracted the tunnel file.
1 |
LT -user [your login email] -key [your access key] |
So, let’s assume if your email ID is myemailid@gmail.com and your user access key is 123asd321 then you’ll need to run the following command in command terminal.
1 |
LT -user myemailid@gmail.com -key 123asd321 |
Once you get a message that your ‘Secure connection established, you may start your tests now’ , you need to enter the following code in your JavaScript code block:
1 2 3 |
var capabilities = { "tunnel" : true //test on localhost network } |
You can also add the capability using LambdaTest Capabilities Generator.
Tunnel Reference: For a full reference of all tunnel features we support, visit our tunnel page.
While performing automation testing using Protractor Selenium on LambdaTest Selenium grid, it is imperative to flag an automation test as either pass or fails. This is completely dependent on your testing requirement with respect to the validation of expected behaviour. You can mark whether an automation test passed or failed by adding the below code fragment in your automation script:
1 |
browser.executeScript("lambda-status=passed"); |
Parallel Testing is one of the most demanding features of LambdaTest Selenium Grid. By parallel testing, you can run more than one test case, simultaneously. This means that Parallel testing would allow you to execute numerous automation test cases altogether. So you execute a single test scenario across different browsers or could run different test scenarios across the same browser but with different browser versions. Wondering how many parallel test cases can you run? That depends entirely on the number of concurrent session under your opted plan.
For instance, if you have a bucket of 100 automated test cases, and the average time for execution of a single test is around 6 minutes. The time taken normally to completely execute all your test cases sequentially would be 600 minutes i.e. 10 hours. However, if you are opting for a plan which offers 2 concurrent sessions then you can perform 2 parallel test cases. This would divide your time in half as the total time taken through parallel testing with 2 concurrent sessions for the above scenario would be 300 minutes i.e. 5 hours. Similarly, if you have got 4 concurrent sessions with you then the time taken would be quarter with respect to sequential testing. This way you could fasten your release cycles as much as you want.
Protractor Test automation framework is really useful in running parallel tests. For instance, in our above example, you may notice that we are running our test on a single environment. If you want to cover multiple environments you would have to change the hard code every time. Or you would have to use arrays, or multi-threading or something similar.
With LambdaTest, you can pace up your test build activities by performing parallel automation testing using Protractor Selenium with JavaScript. Boost quality assurance of your product by performing extensive and fast-paced automated cross browser testing process with LambdaTest parallel testing.
Checkout the same code below to understand it better. You can also find it at our github page here.
To perform parallel automated testing using LambdaTest Automation in JavaScript using Protractor Selenium.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// spec.js describe('Add todo Lists', function () { browser.ignoreSynchronization = true; it('Add Customer Test', function () { browser.get('https://lambdatest.github.io/sample-todo-app/'); browser.driver.findElement(by.name('li1')).then(function (foundElement) { foundElement.click(); }); browser.driver.findElement(by.name('li2')).then(function (foundElement) { foundElement.click(); }); browser.driver.findElement(by.id('sampletodotext')).then(function (foundElement) { foundElement.clear(); foundElement.sendKeys("Yey, Let's add it to list"); }); browser.driver.findElement(by.id('addbutton')).then(function (foundElement) { foundElement.click(); }); var foo = element(by.xpath('//html/body/div/div/div/ul/li[6]/span')); expect(foo.getText()).toEqual("Yey, Let's add it to list"); browser.executeScript("lambda-status=passed"); }); }); |
Here is parallel conf which executes the same tests in parallel.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
exports.config = { // change this to your USERNAME and ACCESSKEY seleniumAddress: 'https://USERNAME:ACCESSKEY@hub.lambdatest.com/wd/hub', // add more browsers to this array for more parallel tests!! multiCapabilities: [{ 'name': 'LambdaTest Parallel', 'build': 'Javascript Example', 'browserName': 'Chrome', 'platform': 'WIN10', 'version':'70.0', 'video': true, //To Enable video recording 'visual': true, //To Enable step by step screenshot 'network': true, //To capture Network logs 'console': true //To capture Console Logs }, { 'name': 'LambdaTest Parallel', 'build': 'JavaScript Example', 'browserName': 'Chrome', 'platform': 'WIN10', 'version':'69.0', 'video': true, //To Enable video recording 'visual': true, //To Enable step by step screenshot 'network': true, //To capture Network logs 'console': true //To capture Console Logs }], //Add test scripts in this array to execute in parallel specs: ['tests/spec.js'] }; |
If you notice, with simple annotations and parameters, you can now run your test suite on multiple browsers every time, without changing the browsers parameters in code files every time.
To prevent over-exploitation of the platform we have added a capacity constraint on the number of tests that can be queued at our platform. Your maximum queue capacity will be dependent upon the number of concurrent sessions your LambdaTest account is eligible for. Below formula will help you calculate the maximum capacity for your queue.
Maximum Queuing Capacity
Maximum number of parallel tests that can be queued = n + 150
Here, n = number of concurrent sessions.
For example, if you have opted for pricing where you can avail up to 10 concurrent sessions. Then the maximum number of parallel test cases that can be queued will be equal to 10 + 150 i.e. 160 parallel test cases. Queuing allows you to manage your test pipeline in a hassle-free manner. LambdaTest would automatically schedule and execute test cases for you.
LambdaTest Queuing Policy
Here you can get more information about LambdaTest Queuing Policy.
Queuing Timeout
There is also a limit on how long a test case can stay in the queue. If your test case stays in the queue for more than 15 minutes, the test case would be timed out and would not be executed.