def LoginGoogleAccount(action_runner,
                       credential,
                       credentials_path=login_utils.DEFAULT_CREDENTIAL_PATH):
    """Logs in into Google account.

  This function navigates the tab into Google's login page and logs in a user
  using credentials in |credential| part of the |credentials_path| file.

  Args:
    action_runner: Action runner responsible for running actions on the page.
    credential: The credential to retrieve from the credentials file
        (type string).
    credentials_path: The string that specifies the path to credential file.

  Raises:
    exceptions.Error: See ExecuteJavaScript()
    for a detailed list of possible exceptions.
  """
    account_name, password = login_utils.GetAccountNameAndPassword(
        credential, credentials_path=credentials_path)

    action_runner.Navigate('https://accounts.google.com/ServiceLogin?continue='
                           'https%3A%2F%2Faccounts.google.com%2FManageAccount')
    login_utils.InputForm(action_runner,
                          account_name,
                          input_id='Email',
                          form_id='gaia_firstform')
    action_runner.ClickElement(selector='#gaia_firstform #next')
    login_utils.InputForm(action_runner, password, input_id='Passwd')
    action_runner.ClickElement(selector='#signIn')
    action_runner.WaitForElement(text='My Account')
Exemplo n.º 2
0
def LoginGoogleAccount(
    action_runner,
    credential='googletest',  # Recommended credential.
    credentials_path=login_utils.DEFAULT_CREDENTIAL_PATH):
    """Logs in into Google account.

  This function navigates the tab into Google's login page and logs in a user
  using credentials in |credential| part of the |credentials_path| file.

  Args:
    action_runner: Action runner responsible for running actions on the page.
    credential: The credential to retrieve from the credentials file
        (type string).
    credentials_path: The string that specifies the path to credential file.

  NOTE: it's recommended to use 'googletest' credential from
  page_sets/data/credentials.json credential since it is a Google test account
  and will not trigger anti-bot verification. Other google credentials are kept
  until all telemetry pages are updated to use the 'googletest' credential.

  Raises:
    exceptions.Error: See ExecuteJavaScript()
    for a detailed list of possible exceptions.
  """
    account_name, password = login_utils.GetAccountNameAndPassword(
        credential, credentials_path=credentials_path)

    action_runner.Navigate('https://accounts.google.com/ServiceLogin?continue='
                           'https%3A%2F%2Faccounts.google.com%2FManageAccount')

    # Wait until either the email or password input is visible.
    action_runner.WaitForJavaScriptCondition2(
        '{{ @a }} || {{ @b }}',
        a=_EMAIL_INPUT_VISIBLE_CONDITION,
        b=_PASSWORD_INPUT_VISIBLE_CONDITION)

    # If the email input is visible, this is the first Google login within the
    # browser session, so we must enter both email and password. Otherwise, only
    # password is required.
    if action_runner.EvaluateJavaScript2(_EMAIL_INPUT_VISIBLE_CONDITION):
        login_utils.InputForm(action_runner,
                              account_name,
                              input_id='Email',
                              form_id='gaia_firstform')
        action_runner.ClickElement(selector='#gaia_firstform #next')

    login_utils.InputForm(action_runner, password, input_id='Passwd')
    action_runner.ClickElement(selector='#signIn')
    action_runner.WaitForElement(text='My Account')
Exemplo n.º 3
0
def LoginChromeAccount(action_runner,
                       credential,
                       credentials_path=login_utils.DEFAULT_CREDENTIAL_PATH):
    """Logs in a Gaia account into Chrome.

  This function navigates the tab into Chrome's login page and logs in a user
  using credentials in |credential| part of the |credentials_path| file.

  Args:
    action_runner: Action runner responsible for running actions on the page.
    credential: The credential to retrieve from the credentials file
        (type string).
    credentials_path: The string that specifies the path to credential file.

  Raises:
    exceptions.Error: See GetWebviewContexts() and ExecuteJavaScript()
      for a detailed list of possible exceptions.
  """
    account_name, password = login_utils.GetAccountNameAndPassword(
        credential, credentials_path=credentials_path)

    action_runner.Navigate('chrome://chrome-signin')

    # Get the Gaia webview context within the sign in extension to create a Gaia
    # action_runner. The action runner will then execute JS in the Gaia context.
    gaia_context = util.WaitFor(lambda: GetGaiaContext(action_runner.tab), 5)
    if not gaia_context:
        raise RuntimeError('Can not find GAIA webview context for sign in.')
    gaia_action_runner = action_runner_module.ActionRunner(gaia_context)

    new_flow = gaia_action_runner.EvaluateJavaScript(
        'document.querySelector("#gaia_firsform") != null')
    gaia_form_id = 'gaia_firstform' if new_flow else 'gaia_loginform'
    login_utils.InputForm(gaia_action_runner,
                          account_name,
                          input_id='Email',
                          form_id=gaia_form_id)
    if new_flow:
        gaia_action_runner.ClickElement(selector='#%s #next' % gaia_form_id)
    login_utils.InputForm(gaia_action_runner,
                          password,
                          input_id='Passwd',
                          form_id=gaia_form_id)
    gaia_action_runner.ClickElement(selector='#signIn')
    action_runner.WaitForNavigate()