Troubleshooting E2E tests is tricky because of all the moving parts and opaqueness of the process. Here are some tips.
Problem: Tests don’t even run
If you’re not even reaching the point where tests are running (failing or succeeding):
- Make sure that the local server is running! If you can’t pull up the app’s
http://localhost:XXXXURL in your browser, make sure that you running the appropriate grunt/gulp task (usually something likegulp connect watch). - Sometimes the WebDriver JAR will become corrupted if the download becomes interrupted. If the Selenium/WebDriver process seems to be hanging, try updating the JAR manually (e.g. with
node_modules/.bin/webdriver-manager update). You can also delete the JAR or the node_module containing it to start from scratch.
Problem: Tests fail
- Figure out which test is failing. Use Protractor’s stack trace if possible; otherwise you can tweak the Protractor config to test one file at a time, or focus on individual tests.
- Try running through the test in the browser yourself to see if you can duplicate the problem. Be sure to check the console for JS errors!
- If the test crashes the Selenium process and the browser window is still open, you can look at it, open the console, inspect the DOM, etc.
- You can slow down or inspect the page at any point in a test using a variety of methods:
- You can call
browser.sleep()anywhere in your tests to pause execution for a short time. - You can pause execution.
- Protractor has a built-in method to take screenshots.
- You can call
- More extensive debugging can be done through the REPL debugger.
Problem: Test fails sometimes, passes other times
There is probably a race condition occurring. Make sure that things like animations are turned off so that the visibility of elements is not time-dependent.
Problem: Times out with Protractor.waitForAngular error
Protractor is designed for use with Angular apps. Because of this, it will wait for Angular to load on the webpage before running any tests. If you want to test a webpage that does not use Angular, you will need to turn off synchronization before calling browser.get():
browser.ignoreSynchronization = false;