-
Notifications
You must be signed in to change notification settings - Fork 23
POP Extension
You will often have certain actions that are performed on many pages in your app. For example, you might have a tab bar, search bar, button, or other element that you want to interact with from any page in your app. You don't want to have separate logic in every page object to interact with these elements so you should define methods in such a way that they are accessible from any page.
The simplest way to achieve this reuse is to add common methods to the BasePage
. This class already has a lot of unrelated code though so we recommend that you subclass BasePage
and add your common, app specific logic there. It would look something like this:
public abstract class MyAppBasePage : BasePage
{
readonly Func<AppQuery, AppQuery> menuButton;
protected MyAppBasePage()
{
menuButton = x => x.Id("menu_icon");
}
public void OpenSideMenu()
{
app.Tap(menuButton);
}
}
Then in each page you can inherit from MyAppBasePage
instead of BasePage
public class HomePage : MyAppBasePage
{
public HomePage()
{
}
}
Which will give you access to the shared methods from your tests
[Test]
public void OpenSideMenuTest()
{
new HomePage()
.OpenSideMenu();
}
Just as you will have certain actions that can be performed on many pages in your app, you will also have certain actions that will be common between tests. For example, in a note app, you might need to add a new note in several tests. You would want to place this method somewhere where you can access it from any test.
You can create a subclass of BaseTestFixture
for methods that do common functionality like this (like we did with BasePage
), but we often just include them in BaseTestFixture
since this class doesn't have much logic in it by default.
You might also have some routines that you want to run at the start of every test. These can go into the setup method in BaseTestFixture
. For example you might want to log in to your app at the start of every test:
[SetUp]
public virtual void BeforeEachTest()
{
AppManager.StartApp();
LogIn();
}
protected void LogIn()
{
new LoginPage()
.EnterCredentials("username@gmail.com", "password")
.Confirm();
}
If you have certain tests that you don't need to log in for, you can put them in a separate class that overrides BeforeEachTest
(just make sure to always call AppManager.StartApp()
at the beginning of BeforeEachTest
if you override the default implementation).
public class PreLogInTests : BaseTestFixture
{
public PreLogInTests(Platform platform)
: base(platform)
{
}
public override void BeforeEachTest()
{
AppManager.StartApp();
}
[Test]
public void SignUpTest()
{
// Sign up logic...
}
}