Skip to main content

✅ 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​

Element Actions​

  • ClickableActions: Contains all clickable element related actions
  • DropDownActions: Contains all drop down element related actions
  • ElementActions: Contains all common methods for element related actions
  • FingerActions: Contains all methods for single finger actions on element / screen related
  • FingersAction: Contains all method for multi finger actions on element / screen
  • TextBoxActions: 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");
}
}