gpt4 book ai didi

selenium - 之前配置的 ChromeDriver 服务仍在运行/使用 Grunt 运行 Webdriver 测试

转载 作者:行者123 更新时间:2023-12-03 13:25:14 25 4
gpt4 key购买 nike

您好,我正在尝试为利用 selenium-webdriver 的 React 应用程序编写 Mocha 测试。

我有几个问题,但帮助其中任何一个都会有所帮助,这样我就可以继续前进。

  1. 首先,理想情况下,我想在不同的测试中共享相同的 webdriver session ,因为我不关心它们运行的​​顺序。我只想加载网页一次,运行所有测试,然后关闭网页。这可能吗?我最初将前后案例放在描述之外的不同文件中,并且工作正常......但后来我无法在任何测试文件中访问驱动程序的实例。

  2. 如果无法共享同一 session ,那么如何解决当我尝试运行两个specFiles时出现的以下错误..

这是错误:

$ grunt test-e2e
Running "mochatest:e2e" (mochatest) task
Running Mocha tests on files
/Users/userName/Desktop/myReactApp/tests/e2e/testSpecOne.js
/Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js

Error: The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration.
at Error (native)
at Object.setDefaultService (/Users/userName/Desktop/myReactApp/node_modules/selenium-webdriver/chrome.js:264:11)
at Object.<anonymous> (/Users/userName/Desktop/myReactApp/tests/e2e/testSpecTwo.js:8:8)
at Module._compile (module.js:556:32)
at loader (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/userName/Desktop/myReactApp/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)

典型的测试如下所示:

import assert from 'assert';
import test from 'selenium-webdriver/testing';
import webdriver, {By, until} from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome';
import chromedriver from 'chromedriver';
import helpers from './helpers.js';

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());


test.describe('Main page', () => {

let driver = new webdriver
.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();

test.before(() => {
helpers.launchTheApp(driver, 'http://localhost:8000/myApp', 'elementOne', 10000);
});

test.after(() => {
helpers.closeTheApp(driver);
})

test.it('Test some items appear', () => {

helpers.checkIfElementIsPresent(driver, By.className, 'elementOne');
helpers.checkIfElementIsPresent(driver, By.className, 'elementTwo');
helpers.checkIfElementIsPresent(driver, By.className, 'elementThree');

});
});

我正在使用 grunt-mocha-test 来运行这些配置如下的测试

e2e:{
options: {
timeout: 3000000,
ignoreLeaks: true,
ui: 'bdd',
run: true,
log: true,
reporter: typeof process.env.FUSION_BUILD_GENERATED === 'undefined' ? 'spec' : 'xunit-file',
grep: grunt.option('grep')
},
src: ['tests/e2e/**/**/*Spec.js']
}

最佳答案

一种可能的解决方案是在隔离环境中运行 session (例如在 Docker 容器中)。然而,尝试使用标准 Selenium 来实现这一点很复杂 - 您必须手动启动和停止容器或使用像 Ansible 这样的基础设施自动化工具。 。这是一个名为 Selenoid 的新的 Selenium 兼容工具。发挥作用。只需在测试中请求两个单独的 session ,它们就会在 Docker 容器内并行运行。这给了你很大的灵 active 。我的发言:https://www.youtube.com/watch?v=TGjpc32my0Y

关于selenium - 之前配置的 ChromeDriver 服务仍在运行/使用 Grunt 运行 Webdriver 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42446927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com