gpt4 book ai didi

selenium-webdriver - vue-cli3 + Electron + chromedriver + selenium-webdriver找不到元素

转载 作者:行者123 更新时间:2023-12-03 12:34:42 32 4
gpt4 key购买 nike

我使用vue-cli项目(已安装了electronic + seleniumWebDriver)与ChromeDriver一起运行测试。

我继续运行chromedriver(安装在vue-cli项目中),然后运行测试文件“node ff.js”。

Electron应用程序在屏幕上运行,但没有任何 react 。然后等待该过程退出,结果变为错误“UnhandledPromiseRejectionWarning:WebDriverError:未知错误:DevToolsActivePort文件不存在”。

我在网络上搜索它,发现其他人认为它可以正常工作的解决方案。它只是在chrome选项中添加了“--disable-dev-shm-usage”。但是它仍然是错误的。

ff.js

const webdriver = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome');

const driver = new webdriver.Builder()
// The "9515" is the port opened by chrome driver.
.usingServer('http://localhost:9515')
.withCapabilities({
chromeOptions: {
args: ['--headless', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage', 'start-minimized'],
// Here is the path to your Electron binary.
binary: './dist_electron/mac/myapp.app/Contents/MacOS/myapp'
}
})
.setChromeOptions(new chrome.Options().addArguments('--remote-debugging-port=7070'))
.forBrowser('electron')
.build()

driver.quit()

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"
}

ps。我尝试过使用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

P.s.之所以没有Spectron,是因为我只使用了 Selenium 测试仪。

最佳答案

经过我尝试几乎推荐的测试库。我结束了testcafe。将首选应用程序路径设置为我的分布式应用程序的二进制文件,然后将页面设置为以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
"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');
});

希望这会帮助某人。

关于selenium-webdriver - vue-cli3 + Electron + chromedriver + selenium-webdriver找不到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56057836/

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