javascript - ERROR: Cannot define class using reflection - Stack Overflow

I'm making App by using this webpageI tried to test e2e-tests, however it didn't work.This pr

I'm making App by using this webpage

I tried to test e2e-tests, however it didn't work.

This program failed to start selenium server. How do I fix this?

npm-v :5.6.0

yarn-v :1.5.1

os -v :10.12.6

Besides, I'm already done with the test that selenium server would work or not. As a result, selenium server also didn't work.

I tried this way to test selenium server

e2e-tests error is below

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 IningMessage.

(/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! [email protected] e2e-tests: wdio

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the [email protected] e2e-tests script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A plete log of this run can be found in:

selenium test result

Selenium 2.0/webdriver protocol bindings implementation with helper mands in nodejs.

For a plete list of mands, visit .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 ponent = shallow(<App />);
  expect(ponent.exists()).toEqual(true);
});

I'm making App by using this webpage

I tried to test e2e-tests, however it didn't work.

This program failed to start selenium server. How do I fix this?

npm-v :5.6.0

yarn-v :1.5.1

os -v :10.12.6

Besides, I'm already done with the test that selenium server would work or not. As a result, selenium server also didn't work.

I tried this way to test selenium server

e2e-tests error is below

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 IningMessage.

(/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! [email protected] e2e-tests: wdio

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the [email protected] e2e-tests script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A plete log of this run can be found in:

selenium test result

Selenium 2.0/webdriver protocol bindings implementation with helper mands in nodejs.

For a plete list of mands, 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 ponent = shallow(<App />);
  expect(ponent.exists()).toEqual(true);
});
Share Improve this question edited Apr 11, 2018 at 8:21 長坂肇 asked Apr 7, 2018 at 9:50 長坂肇長坂肇 491 silver badge3 bronze badges 5
  • Please provide your webdriver dependency (or the package.json) and also a snippet of your testing code – Incepter Commented Apr 7, 2018 at 13:05
  • I added package.json .I thought the part of selenium test result is gonna be testing snippet. if not, i would appreciate to teach me where can I get snippet of my testing code . Thank you – 長坂肇 Commented Apr 8, 2018 at 2:54
  • the snippet I am talking about is the part of your testing code, you don't need to add several dependencies of the webdriver. I already wrote a sample code using webdriver with chai. If interested i can write you a snippet – Incepter Commented Apr 9, 2018 at 13:22
  • Thank you for replying me. I really really appreciate that you wrote me a snipet.Btw i want to know what's wrong with my program?? – 長坂肇 Commented Apr 10, 2018 at 3:30
  • Actually i really do not know because you didn't provide any code snippet of your tests, i will write a sample of the testing code i used – Incepter Commented Apr 10, 2018 at 9:21
Add a ment  | 

3 Answers 3

Reset to default 5

I had this issue as well. The solution for me was to install a JDK 8, as WDIO v4 is apparently not patible with many newer versions of Java. It is an issue with the wdio-selenium-standalone-service.

As discussed in the ments, please visit this link for further information.

Make sure to add this dependency npm install selenium-webdriver and the adequate driver for your favorite browser (please pay attention to versions).

First, start your test file by declaring these variables:

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

Next, build your driver

const driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome()) 
.setChromeOptions(options)  
.build();

Then, you are ready to start hacking, but never forget that everything is ASYNC.

I used this snippet to test login (for example)

// 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();
});

To capture a screenshot, you can use this function:

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();
            });
        }
    );
}

Hope this will help you creating your e-2-e tests.

Regards.

I had the same problem with WebdriverIO v4 and installing Java 8 resolved the problem as remended above.

I'd just want to remend if you want to keep several versions of Java like v11 and v8 you should look at this manual which shows how to toggle between different versions of Java. https://medium./@devkosal/switching-java-jdk-versions-on-macos-80bc868e686a

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744213328a4563438.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信