page object model split object and action in selenium - selenium

I am working in selenium based automation framework.
I have Dashboard page. Dashboard page have 100 and above web elements.
It also contains corresponding actions.
Can I split the web elements in one class file and action in one class file?

The methods in the Page Object depends on the WebElements (in case of using PageFactory) or the locators for those elements. Separating the WebElements and the methods will break the Page Object design pattern and object-oriented class structure in general.
You can find more details and examples in seleniumhq and github docs.

Related

How to structure UI Test methods to reach pages that are behind the login page?

I am trying to find best practices on how to structure UI Test methods in XCTestCase to reach and test app pages that are accessible only after the user logs in.
For me to be able to test the UI of a private Photo View page my test method will need to:
1. Login,
2. Go to the "Albums List" page,
3. Tap on the first album in the list and go to the "Album View" page,
4. Tap on the first photo in the list and go to "Photo View" page,
5. And finally, write assertions to test the UI of a Photo View page.
So, to read the destination page, my UI test needs to go through multiple pages. And if I need to write several UI Test methods for the Photo View Page, then each of my test methods will need to go through the same app pages again and again.
What are the best practices to structure my test methods to test internal app pages?
Shoudl I follow the BDD to do that and write a base class with a method:
givenThatLoginIsSuccessful()
and then create a new Test Case class that extends the base class and has methods like:
// Given
givenThatLoginIsSuccessful()
givenThanAlbumsListPageHasAlbums()
giveThatAlbumViewPageHasPhotos()
// When
whenThumbnailPhotoTapped()
// Then
thenLargeSizePhotoIsVisible()
thenDismissLargePhotoButtonIsEnabled()
thenDownloadLargePhotoButtonIsEnabled()
How do you guys organize your UI Test methods that test internal/deep app pages?
I usually organise my code with PageObject (ScreenObject) pattern.
https://github.com/rzakhar/xctest-assignment/blob/master/TestTarget/TestClass.swift
You can see another implementation of this pattern in this question XCUITest using Robot pattern can't print the erroneous line
There are also other techniques – and they shall be chosen regarding the tests.

TestCafe: Implement Page Object Model

I am trying to implement the Page Object Model in my TestCafe project. How do I implement page transitions from one page to another? For e.g. Move from Login page object to obtain Home page object, both pages have different properties/fields. In Selenium there is a PageFactory and webdriver to work with, how should I implement it in TestCafe?
You don't need to worry about page transitions. TestCafe's Selectors are lazy by default.
Just declare the necessary Page Objects in the fixture file and use it.
See the detailed example in the Use Page Model help topic.

Test cafe - Page Object - Consume Modules

I've been working mainly with selenium (java) and espresso as automation tools. I'm pretty new to test cafe and liking it so far.
I came across this specific situation and was wondering what would be the best way to solve it using javascript or test cafe.
I am using Page Object design on my suite. In addition, I would like those pages to be able to consume many modules that can also be consumed from many other pages.
As an example, let's say I have a Home page that has a Header and Footer modules and I also have a listing page that has a Header, a Footer, and a carousel that shows items (This carrousel also appears on other pages).
I was thinking of creating something like a generic page but not sure if it was the best solution. Any thoughts?
For generic items, create Page object class separately. For example in your case create page object for header/ footer, carousel area and place them in the generic package for better classification.
Invoke them where ever required (i.e. invoke header/ footer in homepage as well as in listing page).

selenium Page factory handle different elements for same page for different users

I have a simple question. I 'm sure many of us might have got into the same situation. I am using page object pattern. Below are the steps i do along the navigation.
Login to my application as one type of user.
Click some link to go form page.
On form page , fills the fields and submit
Logout
On 3) the form object page shows some different input fields depending on the type of the user, which i need to interact with. So how do i deal it within the same page object. Has anybody got into the same situation and have found some decent way of doing this ?
I know it a simple automation script not a Java project where we should be using all oops concepts but still I would go with the following:
Create a parent page class containing the common WebElements and methods.
Create child classes with elements and methods specific to that customer.
In the test, pass a parameter which specifies the type of customer and call the appropriate child class.
If you don't want any of this inheritance stuff, you can also try the following.
Create a page class with elements for all types of customers.
Create generic methods which can take a parameter customerType and perform operations like if customerType==1 do these operations else do these.
Another solution which popped up in my mind, assuming that all fields for a particular customer are mandatory, is as follows.
Create a common class for all elements.
Create a generic method in the page class which follows the condition, if this element is present then enter value.
If you understand the concept of Page object model then this questions will be more clear to you. Yes, inheritance is a big factor here. I suggest you read through this to see how a real page object model should work. And, solution of #3 question is as simple as UI mapping. Something like
#FindBy(how = How.NAME, using = "q")
private WebElement searchBox;
for each elements or similar implementation.
For a complete page object you should map all the elements not depending on the users. The reason being, every time you call that class it will be instantiated and all the mapped elements as well. There is no need of dynamically load the elements If any elements are not used or hidden on the page those will be available and you will not be using them anyway

How to pass data between pages through worklight client API

I want to invoke a procedure in one page and use it in another page, and the response is only used by the next page, so I think JsonStore is not suit for that. Should I define a global var?
Is there any code sample to do such things? Thanks for your help.
I presume by pages you mean different HTML files. If so, that is not recommended, Worklight is intended for single page applications. There are no code samples that show how to do that.
I would recommended having a single HTML page and using something like jQuery.load to inject new HTML / DOM elements. By dynamically injecting new HTML your single/main HTML file shouldn't be too big and you can destroy (i.e. remove from memory / the DOM) unused DOM elements. Searching on Google for page fragments and html templates could help you find examples. The idea is that you don't lose the JavaScript context.
Maybe you can get away with doing a new init to re-initialize JSONStore (it won't delete any the data, just give you access) on every new HTML page and use get to get access to the JSONStore collections to perform operations such as find.