Puppeteer end-to-end test automation with CucumberJS
- To install Puppeteer :
npm install puppeteer --save-dev
- To install Cucumber :
npm install cucumber --save-dev
- To install Junit Reporter :
npm install cucumberjs-junitxml --save-dev
- To install Chai :
npm install chai --save-dev
Define the scripts in package.json as follows :
"scripts": {
"test": "cucumber-js --parallel 1 -f json:report/report.json && node report.js && cat report/report.json | npx cucumber-junit > report/junitreport.xml"
}
Finally execute the tests with npm test
BeforeAll(async() =>{
if (moonHost){
global.browser = await puppeteer.connect({
timeout: 10000,
browserWSEndpoint : 'ws://'+moonHost+':4444/cdtp/chrome',
headless:false
});
}
else{
global.browser = await puppeteer.launch();
}
});
Before(async() =>{
global.context = await global.browser.createIncognitoBrowserContext();
global.page = await global.context.newPage();
});
Scenario Outline: Login to the E-Shop Application with Wrong Password
Given User launched eshop login page
When User logged in eshop using the invalid emailid "<EmailID>" and the invalid password "<Password>"
Then User should not get logged in
Examples:
| EmailID | Password |
| testuser_negative@shop.com | Testing$1 |
When('User logged in eshop using the invalid emailid {string} and the invalid password {string}',async(username,password) =>{
await loginpage.login(username,password);
});
const puppeteer= require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
await page.goto('https://www.example.com/');
await page.screenshot({ path: 'page.png', fullPage: true });
await browser.close();
})();
For more on Puppeteer click here
To know about Moon, how to deploy and use Moon, read the article below : https://ghoshasish99.medium.com/deploy-moon-on-azure-and-google-cloud-607a9604bccc