在Selenium中,下面的代码应该会让您得到一个警告。具体地说,登录弹出窗口:
Alert alert = driver.switchTo().alert();这是如何使用Atata实现的?
发布于 2020-12-31 00:10:51
在Atata中,您可以尝试通过直接通过AtataContext.Current.Driver访问驱动程序实例来执行相同的操作
AtataContext.Current.Driver.SwitchTo().Alert().SetAuthenticationCredentials("username", "password");但是这个WebDriver的功能似乎不能在大多数当前的浏览器中工作。
另一种方法是以https://user:pass@example.com/的形式在URL中传递凭据。最近在Chrome上测试过。
要对Atata执行此操作,可以将Atata基URL设置为"https://example.com/"。然后在某个地方添加以下方法(例如,在一个基础fixture类中):
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();
}此方法将凭据注入基URL。
然后在测试中调用它作为第一个排列操作:
[Test]
public void Test()
{
ApplyBasicAuth("atuser", "atpass");
Go.To<OrdinaryPage>();
// ...
}https://stackoverflow.com/questions/65498485
复制相似问题