Alex Dai Playground

[Protructor] google login

| Comments

google.login()

// 彈跳視窗
browser.driver.getAllWindowHandles().then(function (handles) {
  browser.driver.switchTo().window(handles[1]);
  console.log(handles);
});

browser.driver.sleep(1500);

var emailInput = browser.driver.findElement(by.id('Email'));
emailInput.sendKeys(email);

var nextButton = browser.driver.findElement(by.id('next'));
nextButton.click();

browser.driver.sleep(1500);

var passwordInput = browser.driver.findElement(by.id('Passwd'));
passwordInput.sendKeys(passwd);

var signInButton = browser.driver.findElement(by.id('signIn'));
signInButton.click();

// 帳號未設定 2 步驟驗證, 選擇 手機上接收 google 提示
// 帳號設定好 以 手機上接收 google 提示 為驗證後,則不必在執行此動作
//browser.driver.sleep(10000);
//var challengePickerList = browser.driver.findElement(by.css('#challengePickerList > li:nth-child(3) form'));

browser.takeScreenshot().then(function (png) {
  var stream = fs.createWriteStream('images/challenge.png');
  stream.write(new Buffer(png, 'base64'));
  stream.end();
});

challengePickerList.getOuterHtml().then(function(text) {
  console.log(text);
});

challengePickerList.submit();

browser.driver.sleep(1500);

var submitApproveAccess = browser.driver.findElement(by.id('submit_approve_access'));
submitApproveAccess.click();

// 返回視窗
browser.driver.getAllWindowHandles().then(function (handles) {
  console.log(handles);
  browser.driver.switchTo().window(handles[0]);
});

browser.driver.sleep(3000);

Comments

comments powered by Disqus