optimistic_creeper
optimistic_creeper

Reputation: 2799

How can EventFiringWebDriver be used in Page Object Model

I am trying to use EventFiringWebDriver on Page Object Model. How can this be achieved, since PageFactory.initElements() methods only take WebDriver instances not EventFiringWebDriver instances. Casting EventFiringWebDriver to WebDriver does not work here.

Upvotes: 1

Views: 214

Answers (1)

the-noob
the-noob

Reputation: 1342

Just implement your own page objects by following the principles. You will find out there are a lot of things different from case to case (company to company) and there's no such thing as 'one size fits all'.

Using the same example as page factory I would do something like (very pseudocode):

class Home {
    construct(WebDriver ) {
        this.webdriver = WebDriver
    }

    fillSearch(text) {
        webdriver.findById('x').send_keys(text);

    }

    submit(isValid) {
        if (isValid) {
            return new ResultsPage(this.webdriver);
        } else {
            return self(this.webdriver)
        }
    }
}

Depending on what you're testing you might have to inject also a 'context' in the constructor - for 'polymorphic' pages that have different behaviour depending on the ... context.

I.e. 'logging in' for the first time might take you to a 'tour' page but after that to a 'dashboard' so you might have something like:

class Login {
    construct(WebDriver, context ) {
        this.webdriver = WebDriver
    }

    fillUsername(text) {
        webdriver.findById('username').send_keys(text)
    }

    fillPassword(text) {
        webdriver.findById('password').send_keys(text)
    }

    submit(isValid) {
        if (isValid) {
            if (context.isFirstTimeLogin) {
                return new Tutorial(this.webdriver, context)
            } else {
                return new Dashboard(this.webdriver, context)
            }
        } else {
            return self(this.webdriver)
        }
    }
}

As you can already see the constructor can be an abstract page :)

Upvotes: 1

Related Questions