[JAVA] [Note] Design pattern considered when automating GUI test with Selenium

The product release cycle was about one year, Since we have replaced the system of releasing patches from time to time, we have increased the number of tests.

GUI fluttering is only painful, so I thought about the best design and operation for automation in the future.

Since it is in the prototype stage, it may change, but it is the configuration so far.

Design pattern

The GUI is likely to change and tests are performed on a regular basis. I chose Page Object Design Pattern because I want to make it easy to maintain.

I was allowed to refer to this area. https://www.seleniumhq.org/docs/06_test_design_considerations.jsp#page-object-design-pattern http://ninoseki.hatenablog.com/entry/2013/01/09/212424 http://www.assertselenium.com/automation-design-practices/page-object-pattern/

What is Page Object Design Pattern? A mechanism for creating a test that is resistant to changes by separating the class for each page to be tested and the test case class.

For details, the above link will be helpful, To actually specify screen elements with Selenium methods, create a 〇〇Page class. 〇 〇 Page class is basically created for each screen Test using the 〇〇Page method in the 〇〇Test class.

By creating a class that specifies elements for each page It will be used in various test cases. I think that is the point.

-void if the sod does not return a string etc. without page transition --Returns the destination PageObject if the method involves a page transition --The public method represents the service provided by the page --Hide the inside of the page --Do not write assertions --Method returns another PageObject --You don't have to represent the whole page as a PageObject --Implement as different methods if the same action returns different results

Judgment of test success / failure

You can also judge the test result by checking whether there is a specific element on the displayed screen, etc. I do not know until the screen display collapses. I want to judge whether the GUI is strange to the human eye, so I decided to take a screenshot of the test results and see the results with the human eye.

Switching between multiple browsers

By changing the driver used in Selenium, you can run tests using multiple browsers with the same test code. Create a driver object for the browser you want to specify with a description like DRIVER = new ChromeDriver (); // Chrome object.

I want to switch flexibly here, so Allow the browser to be specified in the configuration file.

Other things that may change, such as URLs and screenshot storage directories, should be cut out into a configuration file and read.

Element specification

It is difficult to set each one, but it seems that there is no choice but to specify it steadily. I hope there is another way.

If possible, create attributes for testing with custom data at development time It seems to be resistant to GUI changes.

reference

Switching by browser http://www.seleniumeasy.com/selenium-tutorials/simple-page-object-model-framework-example

Specifying custom data attributes https://qiita.com/okitan/items/eb8f8e253d0811777215

Recommended Posts

[Note] Design pattern considered when automating GUI test with Selenium
Test with RSpec + Capybara + selenium + chromedriver
[Design pattern] Common logic with Template Method