Created
July 18, 2021 04:26
-
-
Save ankitsadariya/cd370d96ef9d0c28a5d45d4efb515491 to your computer and use it in GitHub Desktop.
Amazon Product search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Amazon product search automation | |
* @author - http://www.softwaretestingtipsandtricks.com/ | |
*/ | |
const puppeteer = require('puppeteer') | |
const chai = require('chai'); | |
const { expect, assert } = require('chai'); | |
const URL = "https://www.amazon.com/"; | |
const selectors = { | |
searchBox : '#twotabsearchtextbox', | |
nextButton : '[class="a-last"]', | |
productLinks : `//span[@class="a-size-medium a-color-base a-text-normal"]`, | |
productTitle : '#productTitle' | |
}; | |
describe.only("Amazon product search automation",()=>{ | |
it("Amazon search",async()=>{ | |
const browser = await puppeteer.launch({headless: false}); | |
const page = await browser.newPage(); | |
await page.setViewport({ width: 1280, height: 800 }) | |
await page.goto(URL); | |
await page.type(selectors.searchBox,'Mobile Phones'); | |
await page.keyboard.press('Enter'); | |
const next = await page.waitForSelector(selectors.nextButton); | |
await next.click(); | |
await page.waitForXPath(selectors.productLinks); | |
const product = await page.$x(selectors.productLinks); | |
await product[2].click(); | |
await page.waitForSelector(selectors.productTitle); | |
const title = await page.$eval(selectors.productTitle, (el) => el.innerText); | |
console.log (title); | |
await page.screenshot({path: 'mobile product.png'}); | |
await browser.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment