Class MobileSessionStateManager

java.lang.Object
com.shaft.gui.element.internal.MobileSessionStateManager

public final class MobileSessionStateManager extends Object
Saves and restores Appium session capabilities and mobile app-state snapshots for one WebDriver session.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    loadAppState(org.openqa.selenium.WebDriver driver, String filePath)
    Restores what is restorable of a previously saved mobile app-state snapshot on a live session: re-activates the app, switches context, and rotates the device when the corresponding capability is supported by the active driver.
    static org.openqa.selenium.MutableCapabilities
    Loads previously saved Appium session capabilities from a JSON file.
    static void
    saveAppState(org.openqa.selenium.WebDriver driver, String filePath)
    Saves a snapshot of the current mobile app state (active app, context, orientation, window size) to a JSON file.
    static void
    saveCapabilities(org.openqa.selenium.WebDriver driver, String filePath)
    Saves the active Appium session capabilities to a JSON file.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • saveCapabilities

      public static void saveCapabilities(org.openqa.selenium.WebDriver driver, String filePath)
      Saves the active Appium session capabilities to a JSON file.
      Parameters:
      driver - active WebDriver (must be a RemoteWebDriver/Appium session)
      filePath - target JSON file
    • loadCapabilities

      public static org.openqa.selenium.MutableCapabilities loadCapabilities(String filePath)
      Loads previously saved Appium session capabilities from a JSON file.

      This is a static method because capabilities must be known before a driver session exists. Example:

      MutableCapabilities capabilities = MobileSessionStateManager.loadCapabilities("target/mobile-session-cache/device.json");
      DriverFactory.getHelper(DriverFactory.DriverType.APPIUM_MOBILE_NATIVE, capabilities);
      
      Parameters:
      filePath - source JSON file
      Returns:
      capabilities restored from the file
    • saveAppState

      public static void saveAppState(org.openqa.selenium.WebDriver driver, String filePath)
      Saves a snapshot of the current mobile app state (active app, context, orientation, window size) to a JSON file.
      Parameters:
      driver - active WebDriver
      filePath - target JSON file
    • loadAppState

      public static void loadAppState(org.openqa.selenium.WebDriver driver, String filePath)
      Restores what is restorable of a previously saved mobile app-state snapshot on a live session: re-activates the app, switches context, and rotates the device when the corresponding capability is supported by the active driver. Unsupported restore steps are skipped silently.
      Parameters:
      driver - active WebDriver
      filePath - source JSON file