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

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.

Related

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).

For Page Object Pattern, when designing the page objects in Selenium, how do you handle multiple modals correctly?

Let me further explain.
You have a page where an application lives. However, upon first login, the user is prompted with a welcome screen that loads in the center of the browser. Like a pop-up from the application. This welcome screen is to help the user get familiar with the app. You can move on through the screens by reading the information and clicking the Continue button. After several of these pop-ups, the application will now be available for testing.
So how would I handle this in the Page Object Pattern using Selenium. Should I have a main page that just has functionality to navigate through these modals? Or should the main page return objects that represent each of the individual modals? Or should each modal be a separate page that I interact with?
Basically, I can think of several options:
ApplicationPage.Modal1.Continue();
or
Modal1.Continue();
Modal2.Continue();
or
ApplicationPage.ContinueThroughModal1();
or
ModalPage.Continue1();
ModalPage.Continue2();
I prefer to look at pages as collection of services. So
should the main page return objects that represent each of the individual modals?
PageObject helps you to improve the maintenance and reduces code duplication. So you can use it as an interface to a page of your AUT.
should each modal be a separate page that I interact with?
I would say - yes. If some future change occurs (in any modal), your PageObj will handle it without changing the test itself. Why not introduce a IModalPopup with Continue() method which will handle the skipping that your tests need. Further more in your MainPage class you can keep a ICollection<IModalPopup> welcomeScreens and iterate those.
Aiming at a full answer here - there is no need to actually go through this
welcome screen that loads in the center of the browser.
Once is enough. Every other test can utilize URL navigation over crawling each middle page. Single test that covers your end-user journey (by clicking required buttons/links) should be sufficient.

Managing session temporarily in ibm mobilefirst?

i have to develop a multipage application that includes invocation of several web services.
My first page has a login page. based on the user input i have to traverse to next page while calling the next web service simultaneously. so obviously this all depends on the login page information that has the userid and password and the response from the web service such as personId etc.
i need to store this information temporarily for a particular session but... how to do this?
There are two kinds of page:
There are the UI states as seen by the user. Your Login page and your Next page are examples of these. From the user's perspective they see a succession of pages.
However you are writing an App, a single controlling thing that is in charge of all those "UI pages". I suppose that you are using MobileFirst to create a hybrid application that is effectively executing in a browser. From that browser's perspective you have a single HTML page. This is important, MobileFirst only works with single-page applications.
Now the browser loads the HTML and JavaScript for your single application page and that JavaScript stays resident as the user moves between the different "UI Pages", so the JavaScript can have variables for keeping the state you are asking about. The actual UI navigation from "page" to "page" is usually done by hiding and revealing DIVs.
Hence your WebService call results will be delivered (asynchronously) to some JavaScript function you define, and in the meantime your code can hide the login page and reveal the next page as required. The login data being held in JavaScript variabes.
All of this is simplified by using a framework such as AngularJS which abstracts the messy details of hiding and revealing and dealing with asynch delivery.

How to use/handle a loader in an MVC app?

in a ASP.NET MVC application that I am currently working there are multiple places in a single page that the user can click. So there is a main menu that's in _layout and for each inidividual page there can be links associated with that page.
I am trying to use a loader which will be shown on every click, mainly where the response takes time but for now it's for every click.
For example in the home page, from the main menu the user can click Students and the loader should come up and hide when the page loads completely. On the students page there can be an ajax call that gets data and binds it to the grid.
So from the time the user clicks on a menu link and the page loads the loader is active/shown. It's hidden once the page loads completely.
The grid can have editing functionality and when the user clicks on any of the CRUD links the loader should show and hide.
I am looking at suggestions on implementing this requirement.
If I can hookup any of the MVC events, that would be cool as I want less of Javascript/jQuery stuff but if Javascript/jQuery is the way then that's fine too.
Currently I don't have anything so anypointers are appreciated.
Assuming AJAX is being used
I don't see a way to keep this server-side without a middle page with a redirect being used (which would just be unnecessary bloat). And, since you're not opposed, you can implement this fairly easily using jQuery and something like blockUI.
I'll let you play with refining the binding to only links you care about, but for now we'll assume all links. Also, MVC should be using jQuery for things like Ajax.Actionlink so we can hijack events like $.ajaxStart and $.ajaxStop:
function showLoadingScreen(enabled){
return enabled ? $.blockUI() : $.unblockUI();
}
$(document).ajaxStart(function(){
showLoadingScreen(true);
}).ajaxStop(function(){
showLoadingScreen(false);
});
Later on you can maybe apply classes to the links you care about and just bind to them (instead of $.ajaxStart) but I'll leave that up to you.