0

I was searching over INTERNET, i didn't find solution for this coding puzzle, let say we have listView and each option will return different screens object. Now I need to create a method that on click on different option based on if/else condtion should return different screens class object. I tried and explored on this coding puzzle, how achieve this, by extending each of may page by using BaseClass or by implementing some interface. in Method, we call return as BaseClass or interface.

possible explanation came as Object orient coding, we can't achieve this. Even if we use BaseClass or interface, than also we can't call sub class or implemented class object

Object will called here will Super class object or Interface object, so Base class or Interface are called here

So, In TestNG or any testcases running using Page Object Model, will not allow us to call instance of those if/else class. We terminate coding statement and Create new Class Object(as per requirement of if/else).

Still, if someone have Idea how to continue calling those methods on listview, without terminating those statement.

  • Firstly welcome Ritesh to community! I suggest you to add details about - your environment, versions of all tools which you are using, platform version, real device/simulator etc – NarendraC Dec 27 '18 at 9:36
1

Suggestion :

Instead of method which will return different screens - If you could verify after selecting this; what you should see & assert if you are able to see, will solve your problem.

1

You can use the below mentioned approach that we usually follow in our software testing companies for mobile app testing services.

In page object model, each fragment will be considered as a separate page. In that page, if you want to use 'if else' we can create a single method to click on all the options present in the list view inside the fragment.

Further, we can create respective pages for the each option inside the fragment, which will be the return type of the clicking function. I am taking the example of Gmail app: Gmail left panel is a fragment which has 3 options(which will also be a fragment itself): Inbox Starred Sent

public <Any>Any clickOptionInsideFragment(String optionToBeClicked)
{
if(driver.findElementById(optionToBeClicked)) when optionToBeClicked=‘Inbox’
{
   return  <Any> new InboxPage;
}
else if (driver.findElementById(optionToBeClicked)) when optionToBeClicked=‘Starred’
   return <Any> new StarredlPage;
}
else if (driver.findElementById(optionToBeClicked)) when optionToBeClicked=‘Sent’
   return <Any> new SentsPage;
}
else if {continue to add the list options}

Based on the option clicked, it will return the respective fragment page.

You can return multiple pages using Any keyword in java as given above

.

  • These are generics - and the suggested code would remove static type checks. Objets of types *Pages should inherent from a base class: iPage, or BasePage, or something called like this... – João Farias Dec 27 '18 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.