178 lines
7.3 KiB
JavaScript
178 lines
7.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { By, Key, until } = require('selenium-webdriver');
|
|
|
|
const { createIdentity } = require('./identityHandler');
|
|
const { getCodeFromEmail } = require('./codeHandler');
|
|
const { clickTime, urlTime, timeoutLoading } = require('./speedHandler').getSpeed();
|
|
|
|
async function createAWSAccount(driver) {
|
|
|
|
try {
|
|
const identity = await createIdentity();
|
|
console.log(identity);
|
|
|
|
await driver.get('https://aws.amazon.com/');
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.wait(until.titleContains('Cloud Computing'), timeoutLoading);
|
|
|
|
await driver.findElement(By.css('button[data-id="awsccc-cb-btn-accept"]')).click();
|
|
await driver.sleep(clickTime);
|
|
|
|
await driver.findElement(By.css('a.lb-btn-p-primary[href="https://portal.aws.amazon.com/gp/aws/developer/registration/index.html?nc2=h_ct&src=header_signup"]')).click();
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.wait(until.titleContains('AWS Console'), timeoutLoading);
|
|
|
|
await driver.findElement(By.id('awsui-input-0')).sendKeys(identity.email);
|
|
await driver.findElement(By.id('awsui-input-1')).sendKeys(identity.first_name + '.' + identity.last_name);
|
|
await driver.findElement(By.id('awsui-input-1')).sendKeys(Key.RETURN);
|
|
await driver.sleep(clickTime);
|
|
|
|
const code = await getCodeFromEmail();
|
|
await driver.findElement(By.id('awsui-input-2')).sendKeys(`${code}`);
|
|
await driver.findElement(By.id('awsui-input-2')).sendKeys(Key.RETURN);
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.findElement(By.id('awsui-input-3')).sendKeys(identity.password);
|
|
await driver.findElement(By.id('awsui-input-4')).sendKeys(identity.password);
|
|
await driver.findElement(By.id('awsui-input-4')).sendKeys(Key.RETURN);
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.findElement(By.id('awsui-radio-button-2')).click();
|
|
await driver.findElement(By.id('awsui-input-5')).sendKeys(identity.first_name + ' ' + identity.last_name);
|
|
|
|
await driver.findElement(By.id('awsui-select-1-textbox')).click();
|
|
await driver.findElement(By.id('awsui-select-1-dropdown-option-74')).click();
|
|
|
|
await driver.findElement(By.id('awsui-input-7')).sendKeys(process.env.AWS_PHONE_NUM);
|
|
|
|
await driver.findElement(By.id('awsui-select-2')).click();
|
|
await driver.findElement(By.id('awsui-select-2-dropdown-option-74')).click();
|
|
|
|
await driver.findElement(By.id('awsui-input-9')).sendKeys(identity.address);
|
|
|
|
await driver.findElement(By.id('awsui-input-11')).sendKeys('Paris');
|
|
await driver.findElement(By.id('awsui-input-12')).sendKeys('Ile-de-France');
|
|
await driver.findElement(By.id('awsui-input-13')).sendKeys(Math.floor(Math.random() * (75017 - 75001 + 1)) + 75001);
|
|
|
|
await driver.findElement(By.id('awsui-checkbox-0')).click();
|
|
await driver.findElement(By.id('awsui-input-13')).sendKeys(Key.RETURN);
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.findElement(By.id('awsui-input-15')).sendKeys(identity.first_name + ' ' + identity.last_name);
|
|
await driver.findElement(By.id('awsui-select-4')).click();
|
|
await driver.findElement(By.id('awsui-select-4-dropdown-option-5')).click();
|
|
|
|
// wait until user finished card verification
|
|
await driver.sleep(urlTime + 4000);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Revolut App');
|
|
}, 300000);
|
|
await driver.sleep(urlTime + 4000);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('you must verify your phone number');
|
|
}, 300000);
|
|
|
|
await driver.findElement(By.id('awsui-select-3')).click();
|
|
await driver.findElement(By.id('awsui-select-3-dropdown-option-74')).click();
|
|
await driver.findElement(By.id('awsui-input-3')).sendKeys(process.env.AWS_PHONE_NUM);
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Verify code');
|
|
}, 300000);
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Select a support plan');
|
|
}, 300000);
|
|
|
|
await driver.findElement(By.className('awsui-button')).click();
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('We are activating your account');
|
|
}, 300000);
|
|
await driver.findElement(By.className('awsui-button')).click();
|
|
await driver.sleep(urlTime);
|
|
|
|
const account = {
|
|
'name': identity.first_name + ' ' + identity.last_name,
|
|
'birthdate': identity.birth_date,
|
|
'email': identity.email,
|
|
'password': identity.password,
|
|
'address': identity.address,
|
|
'phone': process.env.AWS_PHONE_NUM,
|
|
};
|
|
|
|
let accounts = [];
|
|
if (fs.existsSync(path.join(__dirname, '../accounts/aws.json'))) {
|
|
const content = fs.readFileSync(path.join(__dirname, '../accounts/aws.json'), 'utf8');
|
|
accounts = JSON.parse(content);
|
|
}
|
|
|
|
accounts.push(account);
|
|
fs.writeFileSync(path.join(__dirname, '../accounts/aws.json'), JSON.stringify(accounts));
|
|
|
|
await driver.get('https://console.aws.amazon.com/console/home?nc2=h_ct&src=header-signin');
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Root user');
|
|
}, 300000);
|
|
|
|
await driver.findElement(By.id('resolving_input')).sendKeys(identity.email);
|
|
await driver.findElement(By.id('next_button')).click();
|
|
await driver.findElement(By.id('password')).sendKeys(identity.password);
|
|
await driver.findElement(By.id('signin_button')).click();
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Console Home');
|
|
}, 300000);
|
|
|
|
await driver.get('https://eu-west-3.console.aws.amazon.com/console/home?region=eu-west-3');
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Console Home');
|
|
}, 300000);
|
|
|
|
await driver.get('https://eu-west-3.console.aws.amazon.com/ec2/home?#LaunchInstanceWizard:');
|
|
await driver.sleep(urlTime);
|
|
await driver.wait(async () => {
|
|
const pageSource = await driver.getPageSource();
|
|
return pageSource.includes('Launch an instance');
|
|
}, 300000);
|
|
await driver.findElement(By.css('div[data-testid="getting-started-tile-5"]')).click();
|
|
await driver.findElement(By.css('a[role="button"][tabindex="0"][data-analytics="create-key-pair"][data-analytics-type="eventDetail"]')).click();
|
|
await driver.findElement(By.css('input[placeholder="Enter key pair name"]')).sendKeys(identity.first_name);
|
|
await driver.findElement(By.css('button[data-id="key-pair-modal-create"]')).click();
|
|
|
|
const httpsspan = await driver.findElement(By.css('span[data-id="simple-view-https-checkbox"]'));
|
|
const httpscheckbox = await httpsspan.findElement(By.css('input[type="checkbox"]'));
|
|
const HTTPSisSelected = await httpscheckbox.isSelected();
|
|
if (!HTTPSisSelected) {
|
|
await httpscheckbox.click();
|
|
}
|
|
|
|
const httpspan = await driver.findElement(By.css('span[data-id="simple-view-http-checkbox"]'));
|
|
const httpcheckbox = await httpspan.findElement(By.css('input[type="checkbox"]'));
|
|
const HTTPisSelected = await httpcheckbox.isSelected();
|
|
if (!HTTPisSelected) {
|
|
await httpcheckbox.click();
|
|
}
|
|
}
|
|
finally {
|
|
// await driver.quit();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
module.exports = { createAWSAccount }; |