【发布时间】:2020-10-12 20:28:39
【问题描述】:
我知道 Selenium 中有一种方法可以启动浏览器(至少在 Chrome 中),然后附加到该实例。你可以通过 Atata 做同样的事情吗?
【问题讨论】:
标签: c# google-chrome atata
我知道 Selenium 中有一种方法可以启动浏览器(至少在 Chrome 中),然后附加到该实例。你可以通过 Atata 做同样的事情吗?
【问题讨论】:
标签: c# google-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}")。
【讨论】: