Last active
July 31, 2018 16:08
-
-
Save unapersona/ebd15c356eac9ad69158960738423f98 to your computer and use it in GitHub Desktop.
puppeteer-loadtest FdC1
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
{ | |
"name": "egfabrica", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"faker": "^4.1.0", | |
"puppeteer": "^1.6.1" | |
} | |
} |
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
const faker = require("faker"); | |
faker.locale = "es"; | |
const puppeteer = require("puppeteer"); | |
function nif() { | |
let i, | |
numero = parseInt(Math.random() * 100000000), | |
letra = "TRWAGMYFPDXBNJZSQVHLCKET"; | |
i = numero % 23; | |
letra = letra.substring(i, i + 1); | |
return numero + letra; | |
} | |
(async () => { | |
const browser = await puppeteer.launch({ | |
//headless: false | |
}); | |
const page = await browser.newPage(); | |
let c = false; | |
console.log("Abrimos página"); | |
await page.goto("http://fabricadecervezas.servidor.gal", { | |
waitUntil: "networkidle2" | |
}); | |
console.log("Cerramos +18"); | |
await page.waitForSelector("#wpsp-continue"); | |
await page.click("#wpsp-continue"); | |
await page.click("#catapultCookie"); | |
console.log("Vamos a comprar"); | |
await page.goto( | |
"http://fabricadecervezas.servidor.gal/finalizar-compra/?add-to-cart=610" | |
); | |
console.log("Rellenamos formulario"); | |
const options = { delay: 25 }; | |
await page.$("#billing_first_name"); | |
await page.type("#billing_first_name", faker.name.firstName(), options); | |
await page.type("#billing_last_name", faker.name.lastName(), options); | |
await page.type("#billing_last_name2", faker.name.lastName(), options); | |
await page.type("#billing_dni", nif(), options); | |
await page.type("#billing_address_1", faker.address.streetAddress(), options); | |
await page.type("#billing_postcode", faker.address.zipCode(), options); | |
await page.type("#billing_city", faker.address.city(), options); | |
await page.select("#billing_state", "PO"); | |
await page.type("#billing_phone", faker.phone.phoneNumber(), options); | |
const email = faker.internet.userName + "@mailinator.com"; | |
await page.type("#billing_email", email, options); | |
await page.type("#billing_email2", email, options); | |
await page.type("#billing_password", faker.internet.password(), options); | |
console.log("Enviamos"); | |
await page.click("#terms"); | |
await page.click("#place_order"); | |
browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment