Question

I am Selenium Web-driver Automation Enthusiast and Just beginning to make my way through it( I Had no Programming Background). I have completed the the initial Setup that is needed to run tests using Selenium via Eclipse.

I have the Following Question.

I am interest to know about how to setup a Testing Framework to manage all my tests and essentially how eclipse/Selenium can output the results based on the test being performed.

Any help would be appreciated.

Kind Regards -Navdeep

Was it helpful?

Solution

There are several things I would recommend from my own experience in the industry.

  1. Use the Page Object design pattern. This is where you make a java class for each page or significant piece of a page of your web application that you are testing. This will help make your Selenium tests readable and maintainable, and avoid duplication in your code.

  2. Run your tests in parallel. Selenium tests can take a long time to run, and spend precious seconds waiting for WebElements to be present or clickable. (Those seconds add up!) In the case of Selenium, running your tests in parallel just makes sense. You can set up either JUnit or TestNG to handle parallel tests. Personally I would recommend TestNG, although if you're just starting JUnit is slightly less of a learning curve.

  3. Don't be satisfied using your test runner (JUnit, TestNG, etc.) for the output. Although using your test runner in eclipse is a good place to start, you don't want to be stuck with it when you start accumulating a lot of tests and have to keep the results organized. I would recommend that you design a custom reporting framework by outputting your results to an HTML file.

  4. Instead of throwing assertion errors, save your results in a String or a Map. The tricky thing with Selenium is that, unlike unit tests, it takes a lot of processing power and precious time each time you start a new WebDriver and navigate to the page you're testing. So you will very likely want to verify, or "assert" multiple things in one test. However, if you use conventional assert methods, the very first assertion error will stop your test, and you won't be able to keep your browser going and testing other things. (Sometimes this is desirable, but often it is not.) So what you should do instead is store the results of your test in a map. This gives you two advantages:
    1. You can run one final assertion at the end of your test that checks for failures you've stored in your map
    2. You can print the results of your map to an html file and view the results of your selenium tests from your browser.

Hopefully this is helpful and will get you started in the right direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top