我知道在Selenium中有一种方法可以启动浏览器(至少在Chrome中),然后附加到该实例。你能通过Atata做同样的事情吗?
发布于 2020-10-14 00:00:29
以下是启动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}")。
https://stackoverflow.com/questions/64324932
复制相似问题