-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kkoooqq
committed
Nov 9, 2021
1 parent
c2013ac
commit b3dd647
Showing
5 changed files
with
159 additions
and
58 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,86 @@ | ||
const {FakeBrowser} = require('../dist/cjs/FakeBrowser'); | ||
const {spawn, execSync} = require('child_process'); | ||
const path = require('path'); | ||
|
||
process.on('unhandledRejection', (error, p) => { | ||
console.log('=== UNHANDLED REJECTION ==='); | ||
console.dir(error.stack); | ||
}); | ||
|
||
!(async () => { | ||
const dd = require('../device-hub/Windows.json'); | ||
const userDataDir = path.resolve(__dirname, './fakeBrowserUserData'); | ||
|
||
execSync(`rm -rf ${userDataDir}`); | ||
execSync(`mkdir ${userDataDir}`); | ||
|
||
const dd = require('../device-hub/macOS.json'); | ||
const child = spawn('/Applications/Google Chrome 93.0.4577.82.app/Contents/MacOS/Google Chrome', | ||
[ | ||
'--no-default-browser-check', | ||
'--no-first-run', | ||
`--window-position=0,0`, | ||
`--window-size=${dd.window.outerWidth},${dd.window.outerHeight}`, | ||
`--user-data-dir=${userDataDir}`, | ||
'--remote-debugging-port=9222', | ||
], | ||
); | ||
|
||
child.stdout.on('data', (data) => { | ||
}); | ||
|
||
child.stderr.on('data', (data) => { | ||
const dataStr = data.toString(); | ||
if (dataStr.includes('DevTools listening on ')) { | ||
const wsEndPoint = dataStr.substr(dataStr.indexOf('ws://')); | ||
console.log(wsEndPoint); | ||
|
||
launchFBPure(wsEndPoint).then(r => r); | ||
} | ||
}); | ||
|
||
const launchFBPure = async (wsEndPoint) => { | ||
const {addExtra, PuppeteerExtra} = require('puppeteer-extra'); | ||
const pptr = addExtra(require('puppeteer')); | ||
const browser = await pptr.connect({browserWSEndpoint: wsEndPoint}); | ||
const page = await browser.newPage(); | ||
await page.goto('https://nike.com/ca/'); | ||
}; | ||
|
||
const launchFB = async (wsEndPoint) => { | ||
const builder = new FakeBrowser.Builder() | ||
.deviceDescriptor(dd) | ||
.displayUserActionLayer(false) | ||
.doNotHook(false) | ||
.vanillaConnectOptions({ | ||
browserWSEndpoint: 'ws://127.0.0.1:9222/devtools/browser/a060d8a6-82ad-4035-8e24-2fbf35ee4de9', | ||
browserWSEndpoint: wsEndPoint, | ||
}) | ||
.userDataDir('./fakeBrowserUserData'); | ||
.userDataDir(userDataDir); | ||
|
||
const fakeBrowser = await builder.connect(); | ||
|
||
const page = await fakeBrowser.vanillaBrowser.newPage(); | ||
await page.goto('https://nike.com/ca'); | ||
|
||
console.log('wait #hf_title_signin_membership appeared'); | ||
await page.waitForSelector('#hf_title_signin_membership'); | ||
|
||
await page.waitForTimeout(5 * 1000); | ||
|
||
console.log('click login button'); | ||
const signInButton = await page.$('#hf_title_signin_membership'); | ||
await fakeBrowser.userAction.simClickElement(signInButton); | ||
|
||
const emailTextField = await page.$('input[name="emailAddress"]'); | ||
const passwordField = await page.$('input[name="password"]'); | ||
const loginButton = await page.$('.loginSubmit'); | ||
|
||
await fakeBrowser.userAction.simClickElement(emailTextField); | ||
await fakeBrowser.userAction.simKeyboardType('[email protected]'); | ||
|
||
await fakeBrowser.userAction.simClickElement(passwordField); | ||
await fakeBrowser.userAction.simKeyboardType('passowdd+34.3710-'); | ||
|
||
await fakeBrowser.userAction.simClickElement(loginButton); | ||
|
||
|
||
// await fakeBrowser.shutdown(); | ||
})(); | ||
}; | ||
|
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
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
Oops, something went wrong.