Selenium webdriver vue-cli3+;电子+;chromedriver+;selenium webdriver找不到元素
我使用vue cli项目(安装了electron+seleniumWebDriver)对ChromeDriver运行测试 我一直运行chromedriver(安装在我的vue cli项目中),然后运行测试文件“node ff.js” Electron应用程序在屏幕上运行,但什么也没发生。然后等待进程退出,结果变成错误“UnhandledPromisejectionWarning:WebDriverError:unknown error:DevToolsActivePort文件不存在” 我在网上搜索了一下,找到了其他人声称效果不错的解决方案。只需在chrome选项中添加一个“--disable dev shm usage”。但这仍然是一个错误 ff.js package.jsonSelenium webdriver vue-cli3+;电子+;chromedriver+;selenium webdriver找不到元素,selenium-webdriver,webpack,electron,vue-cli-3,Selenium Webdriver,Webpack,Electron,Vue Cli 3,我使用vue cli项目(安装了electron+seleniumWebDriver)对ChromeDriver运行测试 我一直运行chromedriver(安装在我的vue cli项目中),然后运行测试文件“node ff.js” Electron应用程序在屏幕上运行,但什么也没发生。然后等待进程退出,结果变成错误“UnhandledPromisejectionWarning:WebDriverError:unknown error:DevToolsActivePort文件不存在” 我在网上搜
"devDependencies": {
"@types/chai": "^4.1.0",
"@types/mocha": "^5.2.4",
"@vue/cli-plugin-babel": "^3.5.0",
"@vue/cli-plugin-e2e-nightwatch": "^3.6.0",
"@vue/cli-plugin-eslint": "^3.5.0",
"@vue/cli-plugin-typescript": "^3.5.0",
"@vue/cli-plugin-unit-mocha": "^3.5.0",
"@vue/cli-service": "^3.5.0",
"@vue/eslint-config-standard": "^4.0.0",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.3",
"bootstrap": "^4.3.1",
"chai": "^4.1.2",
"chromedriver": "^73.0.0",
"copy-webpack-plugin": "^5.0.2",
"electron": "^4.0.0",
"electron-rebuild": "^1.8.4",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"jquery": "^3.4.0",
"mocha": "^6.1.4",
"mochawesome": "^3.1.2",
"node-sass": "^4.9.0",
"nyc": "^14.0.0",
"popper.js": "^1.15.0",
"sass-loader": "^7.1.0",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "^8.1.0",
"ts-protoc-gen": "^0.9.0",
"typescript": "^3.2.1",
"vue-cli-plugin-electron-builder": "^1.2.0",
"vue-template-compiler": "^2.5.21",
"vuex-module-decorators": "^0.9.8",
"webdriverio": "^5.8.3"
}
"scripts": {
...
"cafe": "testcafe \"electron:/Users/xxx/Documents/ProjectFolder/.testcafe-electron-rc\" \"/Users/xxx/Documents/ProjectFolder/tests/e2e/specs/testcafe.js\""
},
"devDependencies": {
...
"selenium-webdriver": "^4.0.0-alpha.1",
"testcafe": "^1.1.4",
"testcafe-browser-provider-electron": "0.0.8"
}
还有,我试过了ChromeDriver@74.x.x,它仍然会导致相同的错误
事实上,我尝试过Selenium RobotFramework,但仍然发现了相同的错误。我想这是因为我的测试写作或某些设置有问题。(我不擅长测试工具。)
仅供参考
mytest.robot
*** Settings ***
Library Selenium2Library
Variables vars.py
*** Test Cases ***
Foohaha
Create Webdriver Remote desired_capabilities=${binary_location} command_executor=http://localhost:9515
Log To Console ${item.get_attribute('innerHTML')}
[Teardown] Close All Browsers
另外,之所以不使用spectron,是因为我只使用了Selenium。在我尝试了几乎推荐的测试库之后。我最终选择了testcafe。将pref应用程序路径设置为我的分布式应用程序的二进制文件,然后将页面设置为在测试文件中作为html文件打开。主路径是默认值 我就是这样设置的 .testcafe-electron-rc
{
"mainWindowUrl": "app://./index.html",
"electronPath": "/Users/xxx/Documents/ProjectFolder/dist_electron/mac/my-lovely-app.app/Contents/MacOS/my-lovely-app",
"openDevTools": "true"
}
package.json
"devDependencies": {
"@types/chai": "^4.1.0",
"@types/mocha": "^5.2.4",
"@vue/cli-plugin-babel": "^3.5.0",
"@vue/cli-plugin-e2e-nightwatch": "^3.6.0",
"@vue/cli-plugin-eslint": "^3.5.0",
"@vue/cli-plugin-typescript": "^3.5.0",
"@vue/cli-plugin-unit-mocha": "^3.5.0",
"@vue/cli-service": "^3.5.0",
"@vue/eslint-config-standard": "^4.0.0",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.3",
"bootstrap": "^4.3.1",
"chai": "^4.1.2",
"chromedriver": "^73.0.0",
"copy-webpack-plugin": "^5.0.2",
"electron": "^4.0.0",
"electron-rebuild": "^1.8.4",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"jquery": "^3.4.0",
"mocha": "^6.1.4",
"mochawesome": "^3.1.2",
"node-sass": "^4.9.0",
"nyc": "^14.0.0",
"popper.js": "^1.15.0",
"sass-loader": "^7.1.0",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "^8.1.0",
"ts-protoc-gen": "^0.9.0",
"typescript": "^3.2.1",
"vue-cli-plugin-electron-builder": "^1.2.0",
"vue-template-compiler": "^2.5.21",
"vuex-module-decorators": "^0.9.8",
"webdriverio": "^5.8.3"
}
"scripts": {
...
"cafe": "testcafe \"electron:/Users/xxx/Documents/ProjectFolder/.testcafe-electron-rc\" \"/Users/xxx/Documents/ProjectFolder/tests/e2e/specs/testcafe.js\""
},
"devDependencies": {
...
"selenium-webdriver": "^4.0.0-alpha.1",
"testcafe": "^1.1.4",
"testcafe-browser-provider-electron": "0.0.8"
}
testcafe.js
import { Selector } from 'testcafe';
fixture(`Index page`)
.page('/Users/xxx/Documents/ProjectFolder/dist_electron/bundled/index.html');
test('Body > Paragraph contains "Hello World!"', async testController => {
const paragraphSelector = await new Selector('#nav > a.router-link-exact-active.router-link-active');
const txt = await new Selector('#app > div.auth-page > div > div > div > form > fieldset:nth-child(1) > input');
await testController.click(paragraphSelector)
.typeText(txt, 'Peter Parker');
// .expect(paragraphSelector.innerText).eql("Login");//.eql('Login');
});
希望这能帮助别人