简体   繁体   中英

How to test my Java code that is using Selenium?

I have a Java application that is scanning a website using Selenium. It is crawling all the pages of the website. Some of these pages are generated dynamically by selecting a combination values, clicking some buttons. The purpose of this application is to crawl through all the pages of the website and save the HTML source and a screenshot of all the pages it comes across. The content and structure of these webpages keep changing over time.

The application is running fine, but the methods calling the webdriver and fetching the elements to enter a set combination of values and clicking buttons to get to all the pages need to be updated quite often as the HTML structure of the website is changing frequently.

Now my question is that: How can I test the functionality of my Java methods calling the Web Driver using Unit Tests How should I approach the unit tests to test the stability of my code that is finding HTML elements, filling in values, clicking buttons, getting the HTML source. Currently I save a sample HTML file and test my code against it. But since I have to update my code and unit tests along with every HTML structure change, that defeats the purpose of unit tests, if I have to updated my unit tests as well (since the values on the page also change).

Please help me find an efficient or correct approach to testing my code using unit tests.

I have been working on the same feature in this project Revolance UI Monitoring to do reviews on changes in the UI acrross several versions.

To answer your question, I solved the testing problem by using PhantomJS with a mocked website. As you designed yourself the mocked website, you know what should be the expected outcome.

I hope this help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM