ruby - Best practice for checking for error messages using Page Objects -


Best practice to check error messages using page objects, so I have a duplication of my code, where I Checking different error messages. My question is using the Page Objects / Page_ object gem, is there any way that I can remove this duplication? My code:

  def check_error_message Expected_text = "Highlighted field should be filled correctly." CSS = "button-error" real_text = @ browser.span (: class, css) .text actual_text.should == expected_text "span class '# css}' returns the required text: # {expected_text}" span class "# {Css} 'actual text: # {actual_text} "enddef check_password_wek_reference_required_text =" password is very weak, please choose a different password. "Css =" formError "actual_text = @ browser.div (: class, css) .text actual_text .should == Expected_text "Span class '# css}' returns the required text: # {expected_text}" Span class " # Puts 'Css}' actual text: # {actual_text} "end DEF check_deep_email_messes_expected_text =" This email address is already in use by another id. Me account "css =" label-error "actual_text = @ browser.div (Class, css) .text actual_text.should == Expected_text "Span class '# {css}' Expected text: # {expected_text}" spell class '# css}' puts the actual text: # {actual_text} "end < / Code> 

Things to change in methods: expected_text, css, real_ Text.

Page object gem will not help you in this case.

In your case, do not talk about Page object gem. Instead, the common word 'page object pattern' allows to be used because it implements the page object gem.

The aim of the PO pattern is to create an intangible layer between your web page and your test code under the test.

In your case, where you have the statement such as

  actual_text = @ browser.div (: class, css) .text  
< P> P.O. pattern will keep all such secret statements in one place called 'page object'. When this happens, you create ways that direct (often repetitive and non-descriptive) selenium web drivers are used to interact with the page rather than calling. This is a simplification of PO pattern, but explaining to me that it is not intended here.

With these test methods you have made, you have a set of very simple and functional tests that are quite easy to surge. So you can make them quickly, but the instincts you are getting are that you are repeating yourself, if you expand this test suit, even a few hundred trials In the case of, you will also go to a big maintenance nightmare.

In this way, you have to invest in some more complete automation frameworks to help you out. For example, you might consider using cucumber, rspc, capibar or any other test framework that helps you manage test data at a different location and begin to add specific areas of responsibility such as Classes that control errors, classes load test data (CSV, XML, etc.) are to be pumped in their testing cases.

Actually, how am I starting to write a how-to article (book) to create an automation frame, which is beyond the scope of your question and is happening in the field of opinion, etc. , Which is not really compatible with intent stackoverflow (a problem / answer site vs. a forum discussion here, shared opinion, etc.)

I would recommend you invest in this area first when you have special In a question about PO Mani in the form If you do, then post a new question, we will be here! : -)


Comments