Let’s continue on from where we left off in the first part of getting started with CodeceptJS, and start writing some tests.
Run the following command to generate a test file:
You will be asked for the test name and the feature being tested, for this example I entered googleHomepage as the test and Search as the feature being tested.
To make sure everything is up and running, I’ve added two simple actions – I.amOnPage and I.see, the first navigates to our base url defined in the codecept.json file plus /, and the second checks the page for the text ‘makeTheTestFail’. We are hoping this text isn’t found, so we can see an example of the output provided, then we can make the test pass.
As we are using the WebdriverIO framework, we need to install selenium-standalone to execute the tests in the Google Chrome browser running on selenium server.
npm install -g selenium-standalone
Now the selenium-standalone is up and running, we can open the command line window in VS code and run out tests with:
codeceptjs run --steps
Note: if you are seeing a blank browser, the test may be running headless. To view the test running you can remove Nightmare from your codecept.json file for the time-being.
If everything is working correctly (failing), you should see something like this:
Now we have everything working, lets me the test pass.
We can see that the text ‘Gmail’ is in the upper right corner, so lets replace ‘makeTheTestFail’ with that, and run it again.
Nice, we have a successfully passing test. In part 3 we will begin writing the Search test and start performing some more advanced automation techniques.