Initialise a page factory in a step defs file

Question!

I try to enter the code below into the stepdefs file for my feature

var page = new AccountPage();
PageFactory.InitElements(DriverContext.Driver, page);

but it complains wherever i place it, unless i place it in the Given statement like this

[Given(@"the user is on the Accounts page")]
public void GivenTheUserIsOnTheAccountsPage()
{
    var page = new AccountPage();
    PageFactory.InitElements(DriverContext.Driver, page);
    AccountPage.AccountSectionClick();
}

Edit

Ok i have this in the POM file

public class AccountPage : BasePage
{
    public AccountPage()
    {
        PageFactory.InitElements(DriverContext.Driver, this);
    }

and this in my stepdefs

AccountPage page = new AccountPage();

but when i use the 'page' command it doesnt give me a list of methods

By : mass jobs


Answers

does changing to this help?:

[Given(@"the user is on the Accounts page")]
public void GivenTheUserIsOnTheAccountsPage()
{
    var page = new AccountPage();
    PageFactory.InitElements(DriverContext.Driver, page);
    page.AccountSectionClick();
}

I'm guessing as in your edit you still don't really give enough detail as you just show that your class inherits from a base page and give no indication where the method AccountSectionClick is defined.

Imagine you are reading the question without any other knowledge of your code and try to make sure that there is enough information to be able to provide an answer.



Consider writing the entire query in one SELECT (using bracketing, ANDs, ORs), this removes all the inefficient duplicate checking of UNION.

You can try UNION ALL as Pawel-Dyl suggests, but if you can make that work, you can probably write it all in one SELECT, and this gives the optimizer more options.

By : RobertB


I think you could rewrite this as a single query on the status table, using ORs to test each scenario, like so:

SELECT ss.int_tran_id
FROM   status SS
WHERE  ss.stage in ('ACHPayment_Confirmed', 'HIFV4', 'HIFV5_FTRINF', 'Payment_HIFV5_FTRINF')
OR     (ss.stage = 'PREVDAY'
        AND (EXISTS (SELECT NULL
                     FROM   references rf
                     WHERE  ss.int_tran_id = rf.int_tran_id
                     AND    rf.mid_ref IS NOT NULL)
             OR EXISTS (SELECT NULL
                        FROM   app_data ad
                               INNER JOIN ach aa
                                 ON (ad.app_data_id = aa.ach_id)
                        WHERE  ss.int_tran_id = ad.int_tran_id
                        AND    aa.par_number IS NOT NULL)));
By : Boneist


This video can help you solving your question :)
By: admin