[英]How can I do a log-in through ATATA
在 Selenium 中,下面的代碼應該讓您收到警報。 具體來說,一個登錄彈出窗口:
Alert alert = driver.switchTo().alert();
使用 Atata 是如何工作的?
在 Atata 中,您可以嘗試通過直接通過AtataContext.Current.Driver
訪問驅動程序實例來做同樣的事情:
AtataContext.Current.Driver.SwitchTo().Alert().SetAuthenticationCredentials("username", "password");
但是這個 WebDriver 的功能似乎不適用於大多數當前的瀏覽器。
另一種方法是在 URL 中以https://user:pass@example.com/
的形式傳遞憑證。 最近在 Chrome 中測試。
要使用 Atata 執行此操作,您可以將 Atata 基礎 URL 設置為"https://example.com/"
。 然后在某處添加以下方法(例如,在基礎夾具 class 中):
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>();
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.