Created
November 27, 2020 13:01
-
-
Save ragog/9eb7cf838d423d0904b5d07d1ca8335a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { chromium } = require("playwright"); | |
const assert = require("chai").assert; | |
const fs = require('fs'); | |
(async () => { | |
const browser = await chromium.launch(); | |
const page = await browser.newPage(); | |
let rawdata = fs.readFileSync('books.json'); | |
const bookList = JSON.parse(rawdata) | |
let foundList = bookList | |
await page.goto('https://danube-webshop.herokuapp.com//') | |
// await page.click('.topbar > input') | |
// await page.type('.topbar > input', 'for') | |
// await page.click('#button-search') | |
await page.waitForSelector('.shop-content > ul > .preview:nth-child(1) > .preview-title') | |
// halt immediately if results do not equal expected number | |
let resultsNumber = (await page.$$('.preview-title')).length | |
assert.equal(resultsNumber, bookList.length) | |
// remove every element found from the second array... | |
for (i = 0; i < resultsNumber; i++) { | |
const bookTitle = await page.$eval(`.preview:nth-child(${i+1}) > .preview-title`, e => e.innerText) | |
const bookAuthor = await page.$eval(`.preview:nth-child(${i+1}) > .preview-author`, e => e.innerText) | |
foundList = foundList.filter(e => (!((e.title === bookTitle) && (e.author === bookAuthor)))) | |
} | |
// ...then assert that the second array is now empty | |
assert.equal(foundList.length, 0) | |
await browser.close() | |
})() |
This file contains hidden or 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
const puppeteer = require("puppeteer"); | |
(async () => { | |
const puppeteer = require("puppeteer"); | |
const browser = await puppeteer.launch({ headless: false }); | |
const page = await browser.newPage(); | |
const navigationPromise = page.waitForNavigation(); | |
await page.goto("https://www.amazon.com/"); | |
await page.setViewport({ width: 1200, height: 873 }); | |
await page.waitForSelector("#nav-search #twotabsearchtextbox"); | |
await page.click("#nav-search #twotabsearchtextbox"); | |
let randomSixNum = Math.floor(Math.random() * 89999 + 100000); | |
await page.type("#twotabsearchtextbox", randomSixNum.toString()); | |
await navigationPromise; | |
await browser.close(); | |
})(); |
This file contains hidden or 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
doemfiefniawfmo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment