【问题标题】:Atata Attach to Browser InstanceAtata 附加到浏览器实例
【发布时间】:2020-10-12 20:28:39
【问题描述】:

我知道 Selenium 中有一种方法可以启动浏览器(至少在 Chrome 中),然后附加到该实例。你可以通过 Atata 做同样的事情吗?

【问题讨论】:

    标签: c# google-chrome atata


    【解决方案1】:

    这是启动 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 =&gt; x.DebuggerAddress = $"127.0.0.1:{chromePort}")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2020-09-04
      相关资源
      最近更新 更多