-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
82 lines (66 loc) · 2.54 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env node
const dotenv = require("dotenv");
const puppeteer = require("puppeteer");
const chalk = require("chalk");
const prompts = require("prompts");
//ask about email and password
const response = (async function(){
const questions = [
{
type: 'text',
name: 'email',
message: 'Enter your email'
},
{
type: 'password',
name: 'secret',
message: 'Tell me a secret'
},
];
const answers = await prompts(questions);
//setTimeout(() => { return answers; }, 20000);
//console.log(answers);
return "test";//Object.assign({}, answers);
})();
async function main(response) {
const { EXTRACT_URL, FIRSTNAME: firstname, LASTNAME: lastname, DEBUG } = process.env;
const headless = typeof DEBUG === "undefined" || DEBUG == false;
const outputs = ["01-page.png", "02-page.png", "03-page.png"];
const screenshots = [...outputs];
console.log(response);
// create temporary email - add todays date
//const add = new Date().toJSON().slice(0,10).replace(/-/g,'');
const email = "test@mail.ru"; //response.email;
//var pos = email.indexOf("@");
const tempemail = email; //.slice(0, pos) + "+" + add + email.slice(pos);
const password = "12345678"; //response.secret;
// open browser
const browser = await puppeteer.launch({ headless });
// open page
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
await page.goto(EXTRACT_URL);
// enter query string
await page.type("#signupFormStep1 > div:nth-child(1) > input", tempemail);
await page.type("div.flex:nth-child(2) > input:nth-child(1)", password);
await page.screenshot({ path: screenshots.shift() });
// do the query
await page.click(".btn-primary");
// enter query string
await page.type("div.bs-solid:nth-child(1) > input:nth-child(1)", firstname);
await page.type(".ml-2 > input:nth-child(1)", lastname);
await page.select(".appearance-0", "Developer"); //Job title
await page.screenshot({ path: screenshots.shift() });
// do the query
//await page.click(".btn-primary");
await page.screenshot({ path: screenshots.shift() });
// cleanup & steps screenshots
browser.close();
console.log(chalk.blue("\nSee screenshots: "), outputs);
}
// load .env variables, console.log(process.env);
const envConfigurationResult = dotenv.config();
if (envConfigurationResult.error) throw envConfigurationResult.error;
// ask about email and password
//const response = getParameters();
main(response);