错误:无法使用反射定义类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误:无法使用反射定义类相关的知识,希望对你有一定的参考价值。

我正在使用这个webpage制作应用程序

我试图测试e2e测试,但它没有用。

该程序无法启动selenium服务器。我该如何解决?

npm-v:5.6.0

亮入:1.5.1

黄蜂: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);
);
答案

我也有这个问题。我的解决方案是安装JDK 8,因为WDIO v4显然与许多较新版本的Java不兼容。这是wdio-selenium-standalone-service的一个问题。

另一答案

如评论中所述,请访问此link以获取更多信息。

确保为您喜爱的浏览器添加此依赖项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();
);

要捕获屏幕截图,您可以使用此功能:

const captureScreenshot = (driver, savedFile) => 
    console.log('i will save screendshot to ' + savedFile);
    return driver.takeScreenshot()
    .then(
        function(image, err) 
            require('fs').writeFile(savedFile, image,  encoding: 'base64', flag: 'wx' , function(err) 
                if(err) console.log('error occured', err);
                return Promise.resolve();
            );
        
    );

希望这将有助于您创建e-2-e测试。

问候。

以上是关于错误:无法使用反射定义类的主要内容,如果未能解决你的问题,请参考以下文章

Annotation注解

错误:无法使用自定义单元格类设置 UITableViewCell 标签和图像!只能加载单元格样式的数据:字幕不是自定义的

19 异常,反射(转)

java 反射

无法使用自定义类返回类型覆盖方法

反射错误无法设置字段值