微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Atata附加到浏览器实例

如何解决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
{
    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}")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。