C# Atata附加到浏览器实例
我知道在Selenium中有一种方法可以启动浏览器(至少在Chrome中)并在以后附加到该实例。你能通过Atata做同样的事情吗?以下是启动Chrome然后将Atata(ChromeDriver实例)附加到创建的Chrome的示例C# Atata附加到浏览器实例,c#,google-chrome,atata,C#,Google Chrome,Atata,我知道在Selenium中有一种方法可以启动浏览器(至少在Chrome中)并在以后附加到该实例。你能通过Atata做同样的事情吗?以下是启动Chrome然后将Atata(ChromeDriver实例)附加到创建的Chrome的示例 // Set static or find available port number: int chromePort = 9222; // Run Chrome process: Process chromeProcess = new Process {
// 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();
//设置静态或查找可用端口号:
int-chromePort=9222;
//运行Chrome进程:
过程色度过程=新过程
{
StartInfo=新流程StartInfo
{
FileName=@“C:\ProgramFiles(x86)\Google\Chrome\Application\Chrome.exe”,
参数=$”https://demo.atata.io/ --新窗口--远程调试端口={chromePort}--用户数据目录=C:\\Temp“
}
};
chromeProcess.Start();
//创建附加到Chrome的Atata上下文:
ataContext.Configure()
.UseChrome()
.WithOptions(x=>x.DebuggerAddress=$“127.0.0.1:{chromePort}”)
.Build();
//使用Atata执行一些操作:
转到(url:)https://demo.atata.io/products")
.PageTitle.应包含(“产品”);
//清理(只是不要像这里那样做。使用“using(…)”等):
ataContext.Current.Dispose();
chromeProcess.CloseMainWindow();
chromeProcess.Dispose();
要附加到Chrome的主要内容是.useCrome().WithOptions(x=>x.DebuggerAddress=$“127.0.0.1:{chromePort}”)