Created
April 10, 2019 13:21
-
-
Save Eastkap/b05d4947634c1913d1749275caebbabf to your computer and use it in GitHub Desktop.
not working
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
// We'll use Puppeteer is our browser automation framework. | |
const puppeteer = require('puppeteer-core'); | |
const chromeLauncher = require('chrome-launcher'); | |
const req = require('./req') | |
const request = require('request-promise-native') | |
const profile = require('./profiles')[0] | |
const util = require('util') | |
const devices = require('puppeteer/DeviceDescriptors'); | |
const iPhone = devices['iPhone X landscape']; | |
// This is where we'll put the code to get around the tests. | |
/* | |
'iPhone X landscape' | |
*/ | |
const preparePageForTests = async (page) => { | |
// Pass the User-Agent Test. | |
const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'; | |
await page.setUserAgent(userAgent); | |
// Pass the Webdriver Test. | |
await page.evaluateOnNewDocument(() => { | |
Object.defineProperty(navigator, 'webdriver', { | |
get: () => false, | |
}); | |
}); | |
await page.evaluateOnNewDocument(()=>{ | |
Object.defineProperty() | |
}) | |
// Pass the Chrome Test. | |
await page.evaluateOnNewDocument(() => { | |
// We can mock this in as much depth as we need for the test. | |
window.navigator.chrome = JSON.parse(`{"app":{"isInstalled":false,"InstallState":{"DISABLED":"disabled","INSTALLED":"installed","NOT_INSTALLED":"not_installed"},"RunningState":{"CANNOT_RUN":"cannot_run","READY_TO_RUN":"ready_to_run","RUNNING":"running"}},"runtime":{"OnInstalledReason":{"CHROME_UPDATE":"chrome_update","INSTALL":"install","SHARED_MODULE_UPDATE":"shared_module_update","UPDATE":"update"},"OnRestartRequiredReason":{"APP_UPDATE":"app_update","OS_UPDATE":"os_update","PERIODIC":"periodic"},"PlatformArch":{"ARM":"arm","MIPS":"mips","MIPS64":"mips64","X86_32":"x86-32","X86_64":"x86-64"},"PlatformNaclArch":{"ARM":"arm","MIPS":"mips","MIPS64":"mips64","X86_32":"x86-32","X86_64":"x86-64"},"PlatformOs":{"ANDROID":"android","CROS":"cros","LINUX":"linux","MAC":"mac","OPENBSD":"openbsd","WIN":"win"},"RequestUpdateCheckStatus":{"NO_UPDATE":"no_update","THROTTLED":"throttled","UPDATE_AVAILABLE":"update_available"}}}`) | |
window.chrome= window.navigator.chrome; | |
}); | |
// Pass the Permissions Test. | |
await page.evaluateOnNewDocument(() => { | |
const originalQuery = window.navigator.permissions.query; | |
return window.navigator.permissions.query = (parameters) => ( | |
parameters.name === 'notifications' ? | |
Promise.resolve({ state: Notification.permission }) : | |
originalQuery(parameters) | |
); | |
}); | |
// Pass the Plugins Length Test. | |
await page.evaluateOnNewDocument(() => { | |
// Overwrite the `plugins` property to use a custom getter. | |
Object.defineProperty(navigator, 'plugins', { | |
// This just needs to have `length > 0` for the current test, | |
// but we could mock the plugins too if necessary. | |
get: () => [1, 2, 3, 4, 5], | |
}); | |
}); | |
// Pass the Languages Test. | |
await page.evaluateOnNewDocument(() => { | |
// Overwrite the `plugins` property to use a custom getter. | |
Object.defineProperty(navigator, 'languages', { | |
get: () => ['en-US', 'en'], | |
}); | |
}); | |
} | |
const filler = (n,profile)=>{ | |
return new Promise(async(resolve)=>{ | |
let delay = 25; | |
await n.click('#order_billing_name',{delay}) | |
await n.type('#order_billing_name',profile.name+ ' '+ profile.surname,{delay}); | |
await n.waitFor(200) | |
await n.click('#order_email',{delay}) | |
await n.type('#order_email',profile.email,{delay}); | |
await n.waitFor(200) | |
await n.click('#order_tel',{delay}) | |
await n.type('#order_tel',profile.phone,{delay}) | |
await n.waitFor(200) | |
await n.mouse.move(1,1); | |
await n.click('#bo',{delay}) | |
await n.type('#bo',profile.ado,{delay}) | |
await n.waitFor(200) | |
await n.mouse.move(40,23); | |
await n.click('#order_billing_city',{delay}) | |
await n.type('#order_billing_city',profile.city,{delay}) | |
await n.waitFor(200) | |
await n.mouse.move(100,600); | |
await n.click('#zip_label',{delay}) | |
await n.type('#zip_label',profile.postal,{delay}) | |
await n.waitFor(200) | |
await n.type('#order_billing_country','Fr',{delay}) | |
if(profile.cc[0]=='5'){ | |
await n.type('#credit_card_type','M'),{delay}; | |
} | |
await n.click('#cnb',{delay}) | |
await n.type('#cnb',profile.cc,{delay}); | |
await n.waitFor(200) | |
await n.click('#credit_card_month',{delay}) | |
await n.type('#credit_card_month',profile.month,{delay}); | |
await n.waitFor(200) | |
await n.click('#credit_card_year',{delay}) | |
await n.type('#credit_card_year',profile.year,{delay}); | |
await n.waitFor(200) | |
await n.click('#vval',{delay}) | |
await n.type('#vval',profile.code,{delay}); | |
await n.waitFor(200) | |
await n.click('ins[class="iCheck-helper"]',{delay}) | |
await n.waitFor(3500) | |
//await n.evaluate(()=>checkoutAfterCaptcha()); | |
await n.click('input[type="submit"]',{delay}) | |
return resolve() | |
}) | |
} | |
(async () => { | |
const ext1 = 'ublock' | |
// Launch the browser in headless mode and set up a page. | |
const opts = { | |
args: ['--no-sandbox', '--disable-setuid-sandbox', '-disable-gpu', `--disable-extensions-except=${ext1}`, `--load-extension=${ext1}`], | |
chromeFlags:['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu', `--disable-extensions-except=${ext1}`, `--load-extension=${ext1}`], | |
userDataDir: '/tmp/scarlett2', | |
enableExtensions: true, | |
devtools:true, | |
chromePath:'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' | |
} | |
const chrome = await chromeLauncher.launch(opts); | |
opts.port = chrome.port; | |
const resp = await util.promisify(request)(`http://localhost:${opts.port}/json/version`); | |
const {webSocketDebuggerUrl} = JSON.parse(resp.body); | |
const browser = await puppeteer.connect({browserWSEndpoint: webSocketDebuggerUrl}); | |
const page = await browser.newPage(); | |
// Prepare for the tests (not yet implemented). | |
await preparePageForTests(page); | |
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36') | |
//await page.emulate(iPhone); | |
await page.goto('https://mail.google.com') | |
await page.waitFor(2 * 1000) | |
await page.goto('https://www.supremenewyork.com/shop/bags/zwhm4e71f/qbkvce7zu'); | |
let id = await req.findKW(profile.kw); | |
console.log(id); | |
let pids = await req.getPids(id,profile.color,profile.size); | |
//console.log(rep) | |
console.log(pids); | |
await req.atc(page,pids,id); | |
console.log('here') | |
await page.waitFor(5000); | |
await page.goto('https://www.supremenewyork.com/checkout'); | |
await filler(page,profile); | |
await page.waitForSelector('#eastkap') | |
// Clean up. | |
//await browser.close() | |
await browser.disconnect(); | |
await chrome.kill(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment