【问题标题】:How to run testcafe from local on chrome docker image如何在 chrome docker 映像上从本地运行 testcafe
【发布时间】:2020-08-03 23:00:23
【问题描述】:

我不想安装 chrome 来运行 testcafe 并且想使用 chrome docker 映像。 第一步:

docker run -d -p 4444:4444 selenium/standalone-chrome

第二步:

docker container ls
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
3487d6a08310        selenium/standalone-chrome   "/opt/bin/entry_poin…"   About an hour ago   Up About an hour    0.0.0.0:4444->4444/tcp   charming_proskuriakova

Step3:此代码适用于python2.7

from selenium import webdriver

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver=webdriver.Remote(
          command_executor='http://0.0.0.0:4444/wd/hub',
          desired_capabilities=DesiredCapabilities.CHROME)


driver.get("https://www.google.com/")  
print driver.title
driver.close() 

我希望为 testcafe 使用相同的功能。基础代码(test1.js):

    import { Selector } from 'testcafe';

    fixture `Getting Started`
        .page `http://devexpress.github.io/testcafe/example`;

    test('My first test', async t => {
        // Test code
});

在本地 Chrome 上执行:

testcafe chrome test1.js

我正在寻找用 docker 图像替换 chrome 的方法。我知道,chrome 是内置于 testcafe 的,您可以考虑使用“safari”或任何其他浏览器来代替 chrome。 IDea 在 testcafe 中学习使用 docker 镜像。 PS:我不想使用 testcafe/testcafe 图像,因为我的问题不是在 docker 中运行 testcafe,而只是在 docker 中运行浏览器。

【问题讨论】:

    标签: docker testing automated-tests e2e-testing testcafe


    【解决方案1】:

    您能否澄清一下您为什么不想使用 testcafe docker 映像?似乎 selenium/standalone-chrome 图像还包含与 selenium 相关的代码,这些代码侦听 api 请求并在容器内安装的浏览器上运行测试。

    注意:testcafe 没有内置浏览器,它运行本地安装的浏览器。

    在 docker 镜像中运行浏览器的另一种方法是使用远程浏览器功能 (https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#remote-browsers)。您需要使用“远程”浏览器别名运行 tescafe,然后通过“docker run”命令在容器内运行浏览器,并将“http:///browser/connect”链接传递给它

    【讨论】:

    • 如果您熟悉 Selenium Grid,可以通过安装 npmjs.com/package/testcafe-browser-provider-selenium 将其与 TestCafe 一起使用。
    • @Shurygin:我的最终目标是覆盖尽可能多的浏览器,因此使用 testcafe 图像无法实现我的目的。
    • @AndreyBelym:我正在使用它,但它并不涵盖所有组合,如 Windows 浏览器等。
    • @Shurygin:我如何将 url 传递给 docker 浏览器?
    • 您可以使用 docker exec 命令。例如,我只是在带有 docker exec 8 "C:\Program Files\Internet Explorer\iexplore.exe" http://192.168.1.62:62877/browser/connect 的 windows 容器中在 IE 上运行测试
    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多