0

In Selenium, the following code is supposed to get you to an alert. Specifically, a log-in pop-up:

Alert alert = driver.switchTo().alert();

How does this work using Atata?

Yevgeniy Shunevych
  • 1,136
  • 6
  • 11
Bob Webster
  • 153
  • 7

1 Answers1

0

In Atata you can try to do the same by accessing the driver instance directly thru AtataContext.Current.Driver:

AtataContext.Current.Driver.SwitchTo().Alert().SetAuthenticationCredentials("username", "password");

But this WebDriver's functionality seems doesn't work in most current browsers.

Another approach is to pass credentials inside URL in a form of https://user:pass@example.com/. Tested recently in Chrome.

To do that with Atata you can set Atata base URL as "https://example.com/". Then add the following method somewhere (in a base fixture class, for example):

public static void ApplyBasicAuth(string username, string password)
{
    Uri currentBaseUri = new Uri(AtataContext.Current.BaseUrl);

    if (!string.IsNullOrEmpty(currentBaseUri.UserInfo))
        AtataContext.Current.RestartDriver();

    UriBuilder uriBuilder = new UriBuilder(currentBaseUri)
    {
        UserName = username,
        Password = password
    };

    AtataContext.Current.BaseUrl = uriBuilder.ToString();
}

This method injects credentials into base URL.

Then in a test invoke it as a first arrangement action:

[Test]
public void Test()
{
    ApplyBasicAuth("atuser", "atpass");

    Go.To<OrdinaryPage>();
    // ...
}
Yevgeniy Shunevych
  • 1,136
  • 6
  • 11