![](/img/trans.png)
[英]Atata - How to switch to new browser window by using Atata framework?
[英]Atata Attach to Browser Instance
我知道 Selenium 有一種方法可以啟動瀏覽器(至少在 Chrome 中)然后附加到該實例。 你可以通過 Atata 做同樣的事情嗎?
這是啟動 Chrome 然后將 Atata(ChromeDriver 實例)附加到創建的 Chrome 的示例。
// Set static or find available port number:
int chromePort = 9222;
// Run Chrome process:
Process chromeProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
Arguments = $"https://demo.atata.io/ --new-window --remote-debugging-port={chromePort} --user-data-dir=C:\\Temp"
}
};
chromeProcess.Start();
// Create Atata context attached to the Chrome:
AtataContext.Configure()
.UseChrome()
.WithOptions(x => x.DebuggerAddress = $"127.0.0.1:{chromePort}")
.Build();
// Do some actions using Atata:
Go.To<OrdinaryPage>(url: "https://demo.atata.io/products")
.PageTitle.Should.Contain("Products");
// Clean up (just don't do it exactly like here. Use "using (...)", etc.):
AtataContext.Current.Dispose();
chromeProcess.CloseMainWindow();
chromeProcess.Dispose();
附加到 Chrome 的主要內容是.UseChrome().WithOptions(x => x.DebuggerAddress = $"127.0.0.1:{chromePort}")
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.