â Write Test class
Once the page object class is created with locators for all the platforms and the application action class is also created, we can now use it to interact with the page in our tests by calling the corresponding methods from the action class.
tip
Check out all the available static methods to interact with the page in your tests. Following are the available action classes:
Driver actionsâ
AlertActions
: Contains all Alert related actionsContextActions
: Contains all Mobile context actions methodsCookieActions
: Contains all cookies related actionsDriverActions
: Contains all other driver related actionsFrameActions
: Contains all Frames related actionsNavigateActions
: Contains all navigate related actionsWindowActions
: Contains all windows related actions
Element Actionsâ
ClickableActions
: Contains all clickable element related actionsDropDownActions
: Contains all drop down element related actionsElementActions
: Contains all common methods for element related actionsFingerActions
: Contains all methods for single finger actions on element / screen relatedFingersAction
: Contains all method for multi finger actions on element / screenTextBoxActions
: Contains all text box related actions methods
Exampleâ
package io.github.boykaframework.testng.ui.saucedemo;
import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
import static io.github.boykaframework.actions.drivers.WindowActions.onWindow;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static com.google.common.truth.Truth.assertThat;
import io.github.boykaframework.enums.PlatformType;
import io.github.boykaframework.testng.ui.saucedemo.actions.SauceDemoActions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class SauceDemoTest {
private SauceDemoActions sauceDemo;
@AfterMethod (alwaysRun = true)
public void afterMethod () {
onWindow ().takeScreenshot ();
}
@BeforeClass (description = "Setup test class", alwaysRun = true)
@Parameters ({ "platformType", "driverKey" })
public void setupTestClass (final PlatformType platformType, final String driverKey) {
createSession ("SauceDemoTest Persona", platformType, driverKey);
this.sauceDemo = new SauceDemoActions ();
}
@AfterClass (description = "Tear down test class", alwaysRun = true)
public void tearDownTestClass () {
withDriver ().saveLogs ();
clearSession ();
}
@Test (description = "Test login functionality")
public void testLogin () {
this.sauceDemo.verifyLogin ("standard_user", "secret_sauce");
}
}