Update test of Validators DApp
This commit is contained in:
parent
3423e9781b
commit
de9c5a1e60
|
@ -10,10 +10,6 @@ class MetaMaskWallet {
|
|||
|
||||
static createMetaMaskWallet(fileName) {
|
||||
var c=new MetaMaskWallet();
|
||||
//by default
|
||||
//c.account="0xF16AB2EA0a7F7B28C267cbA3Ed211Ea5c6e27411";
|
||||
// c.privateKey="03c06a9fab22fe0add145e337c5a8251e140f74468d72eab17ec7419ab812cd0";
|
||||
// c.networkID=4;//1-main network by default
|
||||
c.parser(fileName);
|
||||
|
||||
return c;
|
||||
|
|
|
@ -3,10 +3,12 @@ const utils = require("./utils/utils");
|
|||
const Constants = require("./utils/constants");
|
||||
const constants = Constants.constants;
|
||||
const dir = require('node-dir');
|
||||
const path = require('path');
|
||||
let faker = require('faker/locale/en');
|
||||
let moment = require('moment');
|
||||
const webdriver = require('selenium-webdriver'),
|
||||
chrome = require('selenium-webdriver/chrome');
|
||||
require("chromedriver");
|
||||
let faker = require('faker/locale/en');
|
||||
|
||||
const metaMaskWallet = require('./MetaMaskWallet.js');
|
||||
const MetaMaskWallet = metaMaskWallet.MetaMaskWallet;
|
||||
|
@ -18,17 +20,128 @@ const timeout = ms => new Promise(res => setTimeout(res, ms))
|
|||
|
||||
const validatorsURL = 'http://localhost:3001'
|
||||
|
||||
const validatorMetaData = {
|
||||
full_name: faker.name.findName(),
|
||||
address: `${faker.address.streetAddress()} ${faker.address.streetName()} ${faker.address.city()}`,
|
||||
us_state: faker.address.state(),
|
||||
zip_code: faker.address.zipCode(),
|
||||
license_id: faker.date.future(),
|
||||
license_expiration: faker.random.alphaNumeric(),
|
||||
};
|
||||
let args = process.argv.slice(2);
|
||||
let validator_num = args[0];
|
||||
|
||||
let files = dir.files(constants.votingKeysFolder, {sync:true});
|
||||
files = files.filter((file) => {
|
||||
let isNotGitKeep = path.basename(file) !== path.basename(`${constants.votingKeysFolder}.gitkeep`);
|
||||
let isNotDsStore = path.basename(file) !== path.basename(`${constants.votingKeysFolder}.DS_Store`);
|
||||
return isNotGitKeep && isNotDsStore;
|
||||
})
|
||||
const votingKeyPath = files[validator_num - 1];
|
||||
|
||||
let votingKeyContent = fs.readFileSync(votingKeyPath, 'utf8');
|
||||
let votingKey;
|
||||
try {
|
||||
votingKey = JSON.parse(votingKeyContent);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
//console.log(votingKey)
|
||||
|
||||
main()
|
||||
|
||||
async function main() {
|
||||
let validatorMetaData = generateValidatorMetadata();
|
||||
|
||||
let options = new chrome.Options();
|
||||
options.addExtensions('./MetaMask_v3.14.1.crx');
|
||||
options.addArguments('start-maximized');
|
||||
options.addArguments('disable-popup-blocking');
|
||||
let driver = new webdriver.Builder()
|
||||
.withCapabilities(options.toCapabilities())
|
||||
.build();
|
||||
|
||||
let wallet = MetaMaskWallet.createMetaMaskWallet(votingKeyPath);
|
||||
|
||||
let metaMask = new meta.MetaMask(driver, wallet);
|
||||
let validatorsPage = await new validators.Validators(driver,validatorsURL);
|
||||
|
||||
metaMask.open();
|
||||
metaMask.activate();
|
||||
|
||||
driver.sleep(4000);
|
||||
|
||||
metaMask.switchToAnotherPage();
|
||||
|
||||
driver.sleep(4000);
|
||||
|
||||
validatorsPage.open();
|
||||
|
||||
driver.sleep(4000);
|
||||
|
||||
validatorsPage.clickSetMetadataTab();
|
||||
|
||||
driver.sleep(1000);
|
||||
|
||||
validatorsPage.fillFirstName(validatorMetaData.first_name);
|
||||
validatorsPage.fillLastName(validatorMetaData.last_name);
|
||||
validatorsPage.fillAddress(validatorMetaData.address);
|
||||
validatorsPage.fillState(validatorMetaData.us_state);
|
||||
validatorsPage.fillZipCode(validatorMetaData.zip_code);
|
||||
validatorsPage.fillLicenseID(validatorMetaData.license_id);
|
||||
validatorsPage.fillLicenseExpiration(validatorMetaData.license_expiration);
|
||||
|
||||
driver.sleep(2000);
|
||||
|
||||
/*let isPageAtindex = await validatorsPage.isPageAtIndex(2);
|
||||
|
||||
if (isPageAtindex) {
|
||||
validatorsPage.switchToAnotherPageByIndex(1);
|
||||
//driver.close();
|
||||
driver.sleep(3000);
|
||||
//validatorsPage.switchToAnotherPageByIndex(1);
|
||||
}*/
|
||||
|
||||
validatorsPage.switchToAnotherPageByIndex(1);
|
||||
|
||||
driver.sleep(2000);
|
||||
|
||||
validatorsPage.clickSetMetadataButton();
|
||||
|
||||
//driver.sleep(2000);
|
||||
|
||||
/*metaMask.switchToAnotherPage();
|
||||
driver.sleep(3000);
|
||||
metaMask.refresh();
|
||||
driver.sleep(2000);
|
||||
let el = await metaMask.isElementPresent(buttonSubmit.buttonSubmit)
|
||||
if (el) {
|
||||
confirmTx(el)
|
||||
} else {
|
||||
console.log("Something went wrong. Let's try once more...")
|
||||
driver.sleep(2000);
|
||||
let el = await metaMask.isElementPresent(buttonSubmit.buttonSubmit)
|
||||
confirmTx(el)
|
||||
}
|
||||
|
||||
async function confirmTx(el) {
|
||||
metaMask.submitTransaction();
|
||||
validatorsPage.switchToAnotherPage();
|
||||
|
||||
driver.sleep(5000);
|
||||
|
||||
let handles = await driver.getAllWindowHandles();
|
||||
for (let i = 0; i < handles.length; i++) {
|
||||
driver.switchTo().window(handles[i]);
|
||||
driver.close();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
function generateValidatorMetadata() {
|
||||
let license_expiration = moment(new Date(faker.date.future())).format('DD/MM/YYYY');
|
||||
const validatorMetaData = {
|
||||
first_name: faker.name.firstName(),
|
||||
last_name: faker.name.lastName(),
|
||||
address: `${faker.address.streetAddress()} ${faker.address.streetName()} ${faker.address.city()}`,
|
||||
us_state: faker.address.state(),
|
||||
zip_code: faker.address.zipCode().split('-')[0],
|
||||
license_id: faker.random.alphaNumeric(10),
|
||||
license_expiration: license_expiration
|
||||
};
|
||||
|
||||
return validatorMetaData;
|
||||
}
|
|
@ -1631,6 +1631,11 @@
|
|||
"resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-4.4.2.tgz",
|
||||
"integrity": "sha512-dF+yxZSojSiI8AXGoxj5qdFWpucndc54Ug+TwlpHFaV7j22MGG+OML2+FVa6xAZtjb/OFFQhOC37Jegx2GbEwA=="
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.20.1",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
|
||||
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="
|
||||
},
|
||||
"mout": {
|
||||
"version": "0.11.1",
|
||||
"resolved": "https://registry.npmjs.org/mout/-/mout-0.11.1.tgz",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"ethereumjs-tx": "^1.3.3",
|
||||
"faker": "^4.1.0",
|
||||
"keythereum": "^1.0.2",
|
||||
"moment": "^2.20.1",
|
||||
"node-dir": "^0.1.17",
|
||||
"node-fetch": "^2.0.0",
|
||||
"password-generator": "^2.2.0",
|
||||
|
|
|
@ -59,10 +59,6 @@ class Ceremony extends page.Page {
|
|||
let keyObject = JSON.parse(keyStoreRaw);
|
||||
return keyObject;
|
||||
}
|
||||
|
||||
open() {
|
||||
this.driver.get(this.URL);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Ceremony = Ceremony;
|
||||
|
|
|
@ -118,9 +118,12 @@ class MetaMask extends page.Page{
|
|||
super.clickWithWait(popupAccount);
|
||||
this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[2].click();");
|
||||
|
||||
|
||||
super.fillWithWait(fieldPrivateKey,this.wallet.privateKey);
|
||||
this.driver.sleep(1500);
|
||||
|
||||
console.log("this.wallet.privateKey:", this.wallet.privateKey)
|
||||
|
||||
super.fillWithWait(fieldPrivateKey, this.wallet.privateKey);
|
||||
this.driver.sleep(2500);
|
||||
super.clickWithWait(buttonImport);
|
||||
// this.driver.sleep(1500);
|
||||
//this.driver.findElement(amountEth).getText().then(console.log);
|
||||
|
|
|
@ -45,6 +45,7 @@ class Page {
|
|||
}
|
||||
|
||||
fillWithWait(element,k) {
|
||||
console.log(element, k)
|
||||
let field = this.driver.wait(webdriver.until.elementLocated(element), Twait);
|
||||
field.sendKeys(k);
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ class Page {
|
|||
this.driver.navigate().refresh();
|
||||
}
|
||||
|
||||
switchToAnotherPage(){
|
||||
switchToAnotherPage() {
|
||||
let dr=this.driver;
|
||||
|
||||
dr.getWindowHandle().then(function (mainWindowHandle) {
|
||||
|
@ -71,5 +72,29 @@ class Page {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
async switchToAnotherPageByIndex(ind) {
|
||||
let dr=this.driver;
|
||||
|
||||
let mainWindowHandle = await dr.getWindowHandle()
|
||||
|
||||
let windowHandles = await dr.getAllWindowHandles();
|
||||
|
||||
dr.switchTo().window(windowHandles[ind]);
|
||||
}
|
||||
|
||||
async isPageAtIndex(ind) {
|
||||
let dr=this.driver;
|
||||
|
||||
let mainWindowHandle = await dr.getWindowHandle()
|
||||
|
||||
let windowHandles = await dr.getAllWindowHandles();
|
||||
|
||||
if (windowHandles.length > ind) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports.Page=Page;
|
|
@ -5,6 +5,16 @@ const webdriver = require('selenium-webdriver'),
|
|||
firefox = require('selenium-webdriver/firefox'),
|
||||
by = require('selenium-webdriver/lib/by');
|
||||
|
||||
const setMetadataTab = by.By.xpath("//*[@id=\"root\"]/section/div[1]/div/div/a[2]");
|
||||
const setMetadataButton = by.By.xpath("//*[@id=\"root\"]/section/div[2]/div/button");
|
||||
const firstNameInput = by.By.xpath("//*[@id=\"firstName\"]");
|
||||
const lastNameInput = by.By.xpath("//*[@id=\"lastName\"]");
|
||||
const addrInput = by.By.xpath("//*[@id=\"address\"]");
|
||||
const stateInput = by.By.xpath("//*[@id=\"us_state\"]");
|
||||
const zipCodeInput = by.By.xpath("//*[@id=\"postal_code\"]");
|
||||
const licenseIdInput = by.By.xpath("//*[@id=\"licenseId\"]");
|
||||
const licenseExpirationInput = by.By.xpath("//*[@id=\"expirationDate\"]");
|
||||
|
||||
class Validators extends page.Page {
|
||||
constructor(driver,URL){
|
||||
super(driver);
|
||||
|
@ -15,8 +25,40 @@ class Validators extends page.Page {
|
|||
this.driver.get(this.URL);
|
||||
}
|
||||
|
||||
open() {
|
||||
this.driver.get(this.URL);
|
||||
clickSetMetadataTab() {
|
||||
super.clickWithWait(setMetadataTab);
|
||||
}
|
||||
|
||||
clickSetMetadataButton() {
|
||||
super.clickWithWait(setMetadataButton);
|
||||
}
|
||||
|
||||
fillFirstName(firstName) {
|
||||
super.fillWithWait(firstNameInput, firstName);
|
||||
}
|
||||
|
||||
fillLastName(lastName) {
|
||||
super.fillWithWait(lastNameInput, lastName);
|
||||
}
|
||||
|
||||
fillAddress(addr) {
|
||||
super.fillWithWait(addrInput, addr);
|
||||
}
|
||||
|
||||
fillState(state) {
|
||||
super.fillWithWait(stateInput, state);
|
||||
}
|
||||
|
||||
fillZipCode(zip_code) {
|
||||
super.fillWithWait(zipCodeInput, zip_code);
|
||||
}
|
||||
|
||||
fillLicenseID(license_id) {
|
||||
super.fillWithWait(licenseIdInput, license_id);
|
||||
}
|
||||
|
||||
fillLicenseExpiration(license_expiration) {
|
||||
super.fillWithWait(licenseExpirationInput, license_expiration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 86e02f194a535ab81a15defede2c593315ae9ac2
|
||||
Subproject commit 10b02df1fe27de00fdacabbb345a9cb44f47bfbd
|
Loading…
Reference in New Issue