For homework, 7. Filter results on Autotrader.ca , I found that sometimes there is a random survey popup displays on the result page which causes my test to fail. Do you know how to deal with it?
I check for it (close button for survey is of class acsCloseButton) before changing each Filter eg. check for it before Selecting Model then check before selecting Year
No problem, basically the test would fail as the survey popup blocks direct clicking the page elements until its closed. I also have a boolean setup that is set to TRUE once the popup is detected and closed so when I check for popup before next filter selection I check for that boolean and if it is still FALSE then check for popup if not then just continue
for any random popup that is displayed always in the same position, the process of handling it is as follows:
1. check if the popup is displayed; this can be done by verifying if the popup title or another significant element is displayed; the checking should be done in a method that returns true if the popup is displayed and false otherwise
2. if the popup is displayed, dismiss it; this can be done usually by clicking the close icon of the popup
change method selects and changes the option of Model filter in this case. First code is in my ModelFilter page object class and last code is in PageFilter base class that filters inherit common stuff from
The method is a composite of multiple methods which achieve one goal - selecting (changing active Model filter value)
select() simply finds the model filter element selects it internally withing my WebDriver wrapper class object. I agree , I could try to move the try/catch simply around the attempt to click the element call
Regarding recursive methods, yes they do add some complexity, but in this case the recursion only happens on error. I shall move the try/catch to catch only the click attempt
I check for it (close button for survey is of class acsCloseButton) before changing each Filter eg. check for it before Selecting Model then check before selecting Year
I see. Thanks.
No problem, basically the test would fail as the survey popup blocks direct clicking the page elements until its closed. I also have a boolean setup that is set to TRUE once the popup is detected and closed so when I check for popup before next filter selection I check for that boolean and if it is still FALSE then check for popup if not then just continue
for any random popup that is displayed always in the same position, the process of handling it is as follows:
1. check if the popup is displayed; this can be done by verifying if the popup title or another significant element is displayed; the checking should be done in a method that returns true if the popup is displayed and false otherwise
2. if the popup is displayed, dismiss it; this can be done usually by clicking the close icon of the popup
3. if the popup is not displayed, keep going
I found a slightly better solution. Check for the modal only if you cannot click element:
Keep in mind, the driver variable you see in my code is my custom wrapper class for WebDriver and not WebDriver itself
one question for you.
what is the purpose of the change() method?
what does it do?
change method selects and changes the option of Model filter in this case. First code is in my ModelFilter page object class and last code is in PageFilter base class that filters inherit common stuff from
In test case class the call is :
then its is called like:
this is what i see:
The method does too many things.
The method tries selecting a model. (one thing)
Then the method tries getting the count. (second thing)
Finally, the method clicks the selected element. (third thing)
If any of these fail, it checks for the modal. (fourth thing)
Finally, it calls itself to change the model (fifth thing).
Recursive methods add complexity.
So your method does 5 different things.
Some of them are about interacting with elements.
One is about getting a count and saving it in a variable that is not local.
A method should do 1 thing only.
It should either do something or return something.
As far as I see, your method does 4 things and returns a value.
Can you try simplifying it?
The method is a composite of multiple methods which achieve one goal - selecting (changing active Model filter value)
select() simply finds the model filter element selects it internally withing my WebDriver wrapper class object. I agree , I could try to move the try/catch simply around the attempt to click the element call
Regarding recursive methods, yes they do add some complexity, but in this case the recursion only happens on error. I shall move the try/catch to catch only the click attempt
As I am never satisfied with my code, I am sure I will change things soon :)
Oleg, are all these methods from the same class?
No, ResultsPage has object of PageFilters class which has object of ModelFilter class which has change method
Hi Oleg,
You should refrain from chaining methods of different classes for the following reasons:
https://www.selenium-training-vancouver.com/forum/questions-public/do-not-chain-methods-of-different-classes
Alex
Yes, I understand when classes are different chaining would make debugging a feat. I am simply going by having Page Elements have their own class like
ResultsPage has an object of ResultsFilter class
ResultFilter class has object of various filters like MakeFilter, ModelFilter etc and has methods to get directly to those like make
Thus call like
would be like : Change model selected in ModelFilter which is in Filters of ResultsPage
I dont want my tests to know anything about Filters classes ...
Something like
would need unnecessary imports into Test class in my opinion