TestCafe: Implement Page Object Model - testing

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.

Related

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

page object model split object and action in 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.

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.

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.

Is there a way to programmatically click links, input info into login forms, etc in Objective-C? (like Mechanize does)

Is there anything similar to Mechanize for Objective-C? I want to enter info into a search bar, select a link, and then extract some information from the webpage
You can either run JavaScript code in the context of your WebView or interact with its DOM yourself.
You can inject javascript into the page to do what you want with stringByEvaluatingJavaScriptFromString. For example to simulate a click, inject:
getElementById('the_button').click();