我正在使用此webpage
制作应用我尝试测试e2e测试,但它没有用。
此程序无法启动selenium服务器。我该如何解决这个问题?
npm-v:5.6.0
yarn-v:1.5.1
os -v:10.12.6
此外,我已经完成了selenium服务器工作与否的测试。因此,selenium服务器也无法正常工作。
我尝试this way来测试selenium服务器
e2e-tests错误低于
ERROR: Cannot define class using reflection chrome at new RuntimeError
(/Users/hajimenagasaka/my-react-todolist/node_modules/webdriverio/build/lib/utils/ErrorHandler.js:144:12) at Request._callback
(/Users/hajimenagasaka/my-react-todolist/node_modules/webdriverio/build/lib/utils/RequestHandler.js:316:39) at Request.self.callback
(/Users/hajimenagasaka/my-react-todolist/node_modules/webdriverio/node_modules/request/request.js:186:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request.
(/Users/hajimenagasaka/my-react-todolist/node_modules/webdriverio/node_modules/request/request.js:1163:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at IncomingMessage.
(/Users/hajimenagasaka/my-react-todolist/node_modules/webdriverio/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:313:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-react-todolist@0.1.0 e2e-tests: wdio
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-react-todolist@0.1.0 e2e-tests script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
硒测试结果
Selenium 2.0/webdriver protocol bindings implementation with helper commands in nodejs.
For a complete list of commands, visit http://webdriver.io/docs.html.
======================================================================
[17:03:28]:ERROR Couldn't find a running selenium server instance on [object Object]/Users/hajimenagasaka/node_modules/chainit/index.js:140
throw err;
^
Error: [init()] <= Couldn't connect to selenium server at makeError (/Users/hajimenagasaka/node_modules/webdriverjs/lib/utils/makeError.js:9:17)
at RequestHandler.<anonymous> (/Users/hajimenagasaka/node_modules/webdriverjs/lib/utils/RequestHandler.js:177:25)
at self.callback (/Users/hajimenagasaka/node_modules/request/request.js:122:22) at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at ClientRequest.self.clientErrorHandler (/Users/hajimenagasaka/node_modules/request/request.js:231:10)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
的package.json
{ "name": "my-react-todolist", "version": "0.1.0", "private": true, "dependencies": {
"chrome": "^0.1.0",
"eslint-plugin-flowtype": "^2.46.1",
"jest-cli": "^22.4.3",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"selenium": "^2.20.0",
"v": "^0.3.0",
"webdriver.js": "^0.1.0",
"webdriverjs": "^1.7.5" },
"devDependencies": {
"chai": "^4.1.2",
"enzyme": "^2.9.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.6.1",
"eslint-plugin-jsx-a11y": "^5.1.0",
"eslint-plugin-react": "^7.1.0",
"react-scripts": "1.0.7",
"react-test-renderer": "^15.6.1",
"selenium-standalone": "^6.5.0",
"wdio-dot-reporter": "0.0.8",
"wdio-mocha-framework": "^0.5.13",
"wdio-selenium-standalone-service": "0.0.9",
"webdriverio": "^4.8.0" },
"scripts": {
"selenium-setup": "selenium-standalone install",
"selenium-start": "selenium-standalone start",
"e2e-tests": "wdio",
"e2e-tests-watch": "wdio wdio.conf.js --watch",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"start":"selenium-standalone start", "selenium": "selenium-standalone", } }
e2etests / test.js
const expect = require('chai').expect;
describe('TodoList App', () => {
it('Should load with the right title', () => {
browser.url('http://localhost:3000/');
const actualTitle = browser.getTitle();
expect(actualTitle).to.eql('Todo List');
});
});
的src / App.test.js
import React from 'react';
import { shallow } from 'enzyme';
import App from './App';
it('App renders without crashing', () => {
const component = shallow(<App />);
expect(component.exists()).toEqual(true);
});
答案 0 :(得分:1)
我也遇到了这个问题。对我来说,解决方案是安装JDK 8,因为WDIO v4显然与许多较新的Java版本不兼容。 wdio-selenium-standalone-service
有问题。
答案 1 :(得分:0)
正如评论中所述,请访问此link以获取更多信息。
确保为您喜欢的浏览器添加此依赖项files = [].slice.call(files).filter( function(s){
return s.type.includes("image") ;
});
和足够的npm install selenium-webdriver
(请注意版本)。
首先,通过声明这些变量来启动测试文件:
driver
接下来,构建您的驱动程序
var chai = require('chai');
var expect = require('chai').expect;
const React = require ('react');
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const By = webdriver.By;
const until = webdriver.until;
const options = new chrome.Options();
options.addArguments('--headless'); // by adding this, chrome will start in headless mode
然后,您已准备好开始黑客攻击,但永远不要忘记所有内容都是const driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(options)
.build();
。
我使用此代码段来测试登录(例如)
ASYNC
要捕获屏幕截图,您可以使用此功能:
// ask the browser to open a page
driver.get('http://localhost:3000/')
/**
* LOGIN PAGE => THEN LOGIN INFO THEN PRESS CONNECT BUTTON
*/
.then(() => driver.findElements(By.xpath('//input')))
.then((inputs) => {
inputs[0].sendKeys('username');
inputs[1].sendKeys('password');
})
.then(() => captureScreenshot(driver, `${__dirname}/images/login-${new
Date().getTime()}.png`))
.then(() => console.log('screenshot captured'))
.then(() => driver.findElement(By.xpath('//button')))
.then((connectButton) => connectButton.click())
/**
* WAIT FOR LOGIN TO FINISH
*/
.then(() => driver.wait(function() {
return driver.findElements(By.xpath("//div[@mode='indeterminate']/div"))
.then(function(elements) {
return elements.length === 0;
})
}), 10000)
.then(() => {
console.log('test done!');
driver.quit();
});
希望这可以帮助您创建e-2-e测试。
问候。
答案 2 :(得分:0)
我在使用WebdriverIO v4时遇到了同样的问题,安装Java 8可以解决上述建议。
我只想建议您是否要保留多个Java版本(例如v11和v8),您应该查看本手册,该手册显示了如何在不同Java版本之间进行切换。 https://medium.com/@devkosal/switching-java-jdk-versions-on-macos-80bc868e686a