Selenium With Javascript
WebdriverIO is an open source testing utility for nodejs. It makes possible to develop selenium tests with Javascript. The article provides more insights on the WebdriverIO framework and its usage.
To run your Selenium tests using WebdriverIO/Javascript, clone the repository, or select and make use of one of the sample tests below to see our platform in action.
All the scripts below makes use of the grid access key. In order to run the test do the following
- Get your access key
- Replace it with <YOUR ACCESS KEY>, in the sample tests below.
Replace <server> with the appropriate URL.
- Public Continuous Testing Cloud - https://cloud.seetest.io/wd/hub/.
- Dedicated Continuous Testing Cloud environment - Your own domain. For example: https://company.experitest.com/wd/hub/
- On-premises Continuous Testing Cloud environment - Your designated URL. For example: https://company.com/wd/hub
Chrome with Javascript Expand source
"use strict";
var webdriverio = require('webdriverio');
function main() {
let options = {
host: '<server>',
protocol: 'https',
port: 443,
path: '',
desiredCapabilities: {
browserName: 'chrome',
accessKey: "<YOUR ACCESS KEY>",
testName: "Javascript Chrome Test"
}
};
webdriverio
.remote(options)
.init()
.url('https://www.seetest.io')
.click("//*[text()='Manual']")
.click("//*[text()='Automation']")
.click("//*[text()='Webinars']")
.getTitle().then(function (title) {
console.log('Title was: ' + title);
})
.getText("(//h2)[1]").then(function(text){
console.log("The title of the first H2 is: ", text);
})
.end()
.catch(function (err) {
console.log(err);
});
}
main();
Firefox with Javascript Expand source
"use strict";
var webdriverio = require('webdriverio');
function main() {
let options = {
host: '<server>',
protocol: 'https',
port: 443,
path: '',
desiredCapabilities: {
browserName: 'firefox',
accessKey: "<YOUR ACCESS KEY>",
testName: "Javascript Firefox Test"
}
};
webdriverio
.remote(options)
.init()
.url('https://www.seetest.io')
.click("div > nav > div > ul > li:nth-child(1)")
.click("//*[text()='Automation']")
.click("//*[text()='Webinars']")
.getTitle().then(function (title) {
console.log('Title was: ' + title);
})
.getText("(//h2)[1]").then(function(text){
console.log("The title of the first H2 is: ", text);
})
.then(function(){
console.log
})
.end()
.catch(function (err) {
console.log(err);
});
}
main();
IE with Javascript Expand source
"use strict";
var webdriverio = require('webdriverio');
function main() {
let options = {
host: '<server>',
protocol: 'https',
port: 443,
path: '',
desiredCapabilities: {
browserName: 'internet explorer',
accessKey: "<YOUR ACCESS KEY>",
testName: "Javascript IE Test"
}
};
webdriverio
.remote(options)
.init()
.url('https://www.seetest.io')
.click("//*[text()='Manual']")
.click("//*[text()='Automation']")
.click("//*[text()='Webinars']")
.getTitle().then(function (title) {
console.log('Title was: ' + title);
})
.getText("(//h2)[1]").then(function(text){
console.log("The title of the first H2 is: ", text);
})
.end()
.catch(function (err) {
console.log(err);
});
}
main();
Before you begin, make sure to install webdriverio bindings for Selenium. Also make sure that you have the latest Node.js installed on your machine.
In your terminal or command line, run the command:
npm install --save webdriverio
If you clone the repository, simply run the command:
npm install --save