【问题标题】:How to run scripts on Selenoid browser如何在 Selenoid 浏览器上运行脚本
【发布时间】:2020-08-26 14:28:13
【问题描述】:

我一直在尝试设置 Selenoid 以用于我的自动化设置的并行测试,因为我有数百个测试用例要运行。

这是我尝试过的。

1) 已安装 Docker 桌面

2) 使用此命令下载 Selenoid 容器

    docker run -d --name selenoid -p 4444:4444 -v ~/.aerokube/selenoid/:/etc/selenoid/:ro     
-v /var/run/docker.sock:/var/run/docker.sock    
aerokube/selenoid:latest-release

3) Selenoid 和 Selenoid UI 已在 Docker 上启动并运行。 为了检查这个设置,我已经这样做了:

当我在浏览器中输入 http://localhost:4444/status 时,它会将我带到一个包含以下文本的页面:

 {"total":5,"used":0,"queued":0,"pending":0,"browsers":{}}

当我在浏览器中输入http://localhost:8080/ 时。它会将我带到 Selenoid UI 页面,其中包含文本 No Sessions yet

我有一个使用“docker pull selenoid/chrome”命令拉取的 chrome 浏览器图像。

当我尝试自动化一个简单的脚本来访问在 Selenoid 容器上运行的浏览器时,我收到了一个错误

 Requested environment is not available (WARNING: The server did not provide any stacktrace information)



DesiredCapabilities dcap = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
dcap.setCapability(ChromeOptions.CAPABILITY, options);
dcap.setCapability("enableVNC", true);
dcap.setBrowserName("chrome");

RemoteWebDriver driver = new RemoteWebDriver(
    URI.create("http://localhost:4444/wd/hub").toURL(), 
    dcap
);

String driverPath = "C:\\ABC\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverPath);

// Get URL
driver.get("https://www.google.com/");
// Print Title
System.out.println(driver.getTitle()); 

我在这里遗漏了什么重要的东西吗?请指导我。谢谢。

【问题讨论】:

    标签: docker selenium selenium-webdriver selenium-chromedriver selenoid


    【解决方案1】:

    您至少应该在~/.aerokube/selenoid/ 中创建一个browsers.json 文件,其中 Selenoid 将读取可用浏览器版本的列表以及要使用的 Docker 映像。

    我建议您使用我们名为cm 的自动安装工具,它会自动完成您的所有操作。将此工具二进制文件下载到您的工作站安装就像发出两个命令一样简单:

    $ ./cm selenoid start --vnc
    $ ./cm selenoid-ui start
    

    【讨论】:

    • 这正是我所做的。但是对于 Chrome,我必须使用“path”:“/”而不是“path”:“/wd/hub”。在 browsers.json 文件中。但在官方文档中明确提到。感谢您提出cm。这要容易得多。
    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多