2

we have a business centered around some sort of web application with steps like a wizard:

  1. Landing page with information
  2. Page where user can enter personal information (name, email, phone, address, ...)
  3. Page where user can enter information on the item they are interested in. This page can contain quite a lot of fields to enter information in.
  4. Summary page with confirmation button
  5. Thank you page after confirming the subscription

The pages themselves are not that difficult, the problem lies in the fact that we provide this flow for several business lines in different countries.

So page 2 varies in the entry fields: US address is different than UK address, etc.

Page 3 varies the most because we sell different kind of subscriptions that require different info.

So we have product1_US, but also product1_UK, etc Also: product2_US, product2_UK, etc.

In the code of the application there is some shared code, but also each combination of product, country has specific code.

Since the business wants to roll out more and more products in more countries, I don't think it is feasible to make PageObjects for each combination (product,country).

How best to structure my code for this?

Should I make an almost empty skeleton PageObject that I fill in for each combination (product,country)? Should I model parts of the page for each combination and combine the parts into the skeleton class?

Since application is made in C#, we will most likely also be using C# with NUnit.

1

You could make a base POM that your country specific POMs inherit from:

public class BaseProductPOM
{
    // all common selectors and methods
}

And in another .cs file:

public class UsProductPOM : BaseProductPOM
{
    public UsProductPom(IWebDriver driver)
    {
        PageFactory.InitElements(driver, this);
    }

    // country specific selectors and methods
}
0

I recently released a test automation framework which allows tests to run without writing custom page objects. It sounds like you could benefit from a similar approach that I took to creating page objects on the fly.

(Edit: Of course, this code is in Java while you are looking for C# help but the translation from Java to C# should be easy.)

My code is here: https://github.com/saiscode/kheera/blob/master/src/main/java/in/ramachandr/automation/core/extras/

Specifically, look at the -map method which attaches web elements to named strings.

protected void map(AbstractPage p) {
    getBys();
    List<WebElement> elements = new ArrayList<WebElement>();
    for (By by : bys) {
        elements.addAll(driver.findElements(by));
    }
    PageFactory.initElements(driver, this);
    String[] tokens = locators.split(",");
    for(WebElement w: elements) {
        for (String s : tokens) {
            try{
                String attr = w.getAttribute(s);//throws StaleElementReferenceException
                if (attr != null) {
                    nameElementMap.put(attr, w);
                }
            }catch(StaleElementReferenceException se){
                //ignoring elements which have become stale because
                //a stale object shouldn't have to be referenced 
                //by an automation script
            }
        }
    }
}

Framework

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.