I have written this test with selenium webdriver and nodejs, I have added 30 seconds before submitting form and checking title of page to see if it is success or not,since I use browser compatibility tool the test is runing on remote computer so page load can take around 20 minutes, Is there a better way to do it with driver.wait or sleep.Button shouldnt be clicked before fields are filled and check title function has to run after button is click.
/*
LambdaTest selenium automation sample example
Configuration
----------
username: Username can be found at automation dashboard
accessKey: AccessKey can be generated from automation dashboard or profile section
Result
-------
Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid
*/
const webdriver = require('selenium-webdriver');
/*
Setup remote driver
Params
----------
platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari)
version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
*/
// gridUrl: gridUrl can be found at automation dashboard
const GRID_HOST = 'hub.lambdatest.com/wd/hub';
function fillandsubmitform() {
// Setup Input capabilities
const capabilities = {
platform: 'macOS Mojave',
browserName: "Safari",
version: '12.0',
resolution: '1280x960',
network: true,
visual: true,
console: true,
video: true,
name: 'Form', // name of the test
build: 'NodeJS build' // name of the build
}
// URL: https://{username}:{accessKey}@hub.lambdatest.com/wd/hub
const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;
// setup and build selenium driver object
const driver = new webdriver.Builder()
.usingServer(gridUrl)
.withCapabilities(capabilities)
.build();
// navigate to a url, search for a text and get title of page
driver.get('https://.....');
driver.findElement(webdriver.By.css('#_contactform_topic > option:nth-child(3)')).click();
driver.findElement(webdriver.By.id('lastname')).sendKeys('testSurname');
driver.findElement(webdriver.By.id('_hemail')).sendKeys('test@gmail.com');
driver.findElement(webdriver.By.id('_ePhone')).click();
driver.findElement(webdriver.By.id('_Morning')).click();
setTimeout(function(){
driver.findElement(webdriver.By.xpath("//button[contains(text(),'Send')]")).click();
}, 30000);
setTimeout(function(){
check_title();
}, 30000);
function check_title() {
var promise = driver.getTitle().then(function(title) {
if (title === 'Thank you for submission') {
console.log('Success');
driver.quit();
return true;
} else {
console.log('Failed --' + title);
driver.quit();
}
});
return promise;
}
}
fillandsubmitform();
Aucun commentaire:
Enregistrer un commentaire