New to Selenium E2E with reaction

I created a hotfix fix project, .json packages have the usual suspects:

  • prestart
  • start
  • list
  • test
  • and etc.

I use Selenium for my E2E structure. I have the following test:

it('should launch a browser', () => { const By = webDriver.By; let driver = new webDriver.Builder() .forBrowser('chrome') .build(); // verify Continue button exist on page driver.navigate().to('http://localhost:3000').then(() => driver.findElement(By.id('submitButton')).getAttribute('value')) .then(buttonValue => expect(buttonValue).toEqual('Continue')); }); 

If I do npm start , my site will start, and my E2E will launch an additional Chrome browser and go to my site: localhost:3000 . Test completed successfully.

My question is: how do I run E2E separately, without having my site side by side using npm start .

I am new to React and Selenium, in case I do not have enough information about this post, I apologize in advance.

+5
source share
1 answer

Well, since you didn’t take the time to update the question information with the NPM "scripts" object, then I will try to take a picture in the dark.

First of all, due to your wording, I can interpret your question in two ways:

  • a.) you want to run E2E tests separately, without your server (which runs through npm start );
  • b.) , you want to run E2E tests through npm start without starting your server;

a.) If you want to run your scripts separately, then, seeing that you are using Mocha , you can run them through: ./node_modules/.bin/mocha <pathToTests>/<testFile> .

Now, since you stated in your question that you are using the npm test script, then this should be the best switch for linking the execution of E2E tests to:

package.json (Scripts object):

 "scripts": { "test": "mocha --reporter spec <pathToTests>/<testFile>", "start": "node <yourServerName>.js" }, 

Note that mocha <pathToTests>/<testFile> equivalent to ./node_modules/.bin/mocha <pathToTests>/<testFile> because NPM searches for binaries inside node_modules/.bin and when Mocha was installed, it set it to this directory.

Note. . Many packages have a bin or .bin section that declares scripts that can be called from NPM, similar to Mocha. If you want to know what other binaries you can run this way, just type ls node_modules/.bin .


b.) . In this care, I think your problem may be related to the fact that NPM did not execute some script values ​​based on the contents of the package. In particular, if you have a server.js file in the root directory of your package, then npm will start the server.js command by server.js .

So, if you start E2E tests via npm start , having this ( "start": "mocha <pathToTests>/<testFile>" ) in package.json is the server.js in the root folder of your package, then npm will start the command by default node server.js .

In this case, you can either move the script server to another location in the project, or change the switch you use to run the E2E tests ( see section b.) ).

Hope this solves your problem, and if not, we look forward to this package.json "scripts" object so that we can really see what is happening. :)

Hooray!

+5
source

Source: https://habr.com/ru/post/1268816/


All Articles