GPT Driver User Guide
GPT Driver SDK
GPT Driver SDK
  • 👋Welcome
  • Overview
    • 💡Why GPTD
    • SDKs
      • Prerequisites
      • Python
        • Setup
        • Examples
        • Reference
      • Typescript
        • Setup
        • Examples
        • Reference
      • Java
        • Setup
        • Examples
          • GPT Driver + TestNG
          • GPTD + Lambdatest
          • GPTD + SauceLabs
          • GPT Driver + BrowserStack
        • Reference
        • Use within Android
      • Android Native (Java/Kotlin)
        • Setup
        • Example
        • Reference
      • Swift
        • Setup
        • Usage
Powered by GitBook
On this page
  1. Overview
  2. SDKs
  3. Java
  4. Examples

GPTD + SauceLabs

import io.appium.java_client.AppiumDriver;
import io.mobileboost.gptdriver.GptDriver;
import org.jetbrains.annotations.NotNull;
import org.openqa.selenium.MutableCapabilities;
import org.testng.annotations.Test;

import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * Simple example of how to use SauceLabs with Appium and GptDriver for mobile testing.
 */
public class SauceLabsTest {

    String userName = "..."; // Add your SauceLabs username here
    String accessKey = "..."; // Add your SauceLabs access key here
    String appURL = "..."; // Replace with your actual app URL or storage ID from SauceLabs
    String hub = "https://ondemand.eu-central-1.saucelabs.com:443/wd/hub";

    AppiumDriver driver;
    GptDriver gptDriver;

    @NotNull
    private MutableCapabilities getCapabilities() {
        MutableCapabilities caps = new MutableCapabilities();
        caps.setCapability("platformName", "Android");
        caps.setCapability("appium:app", appURL);
        caps.setCapability("appium:deviceName", "Android GoogleAPI Emulator");
        caps.setCapability("appium:platformVersion", "12.0");
        caps.setCapability("appium:automationName", "UiAutomator2");

        MutableCapabilities sauceOptions = new MutableCapabilities();
        sauceOptions.setCapability("username", userName);
        sauceOptions.setCapability("accessKey", accessKey);
        sauceOptions.setCapability("build", "<Your build name>");
        sauceOptions.setCapability("name", "<Your test name>");
        sauceOptions.setCapability("deviceOrientation", "PORTRAIT");
        caps.setCapability("sauce:options", sauceOptions);

        return caps;
    }

    @Test
    public void TestWithGptDriver() throws Exception {

        System.out.println("Creating driver with SauceLabs...");
        driver = new AppiumDriver(new URL(hub), getCapabilities());
        
        // Initialize a GPT Driver instance with your GPT Driver API KEY
        gptDriver = new GptDriver("<api_key>", driver, hub);

        // Using GptDriver to interact with the app
        gptDriver.execute("perform a login with email (test@test.com) and password (Test1234)");
        gptDriver.execute("check that you can see your account stats incl. an inbox count");
        gptDriver.execute("perform a logout");
        
        // End the session
        gptDriver.setSessionStatus("success");
        driver.executeScript("sauce:job-result=" + "passed");
        driver.quit();
    }
}

PreviousGPTD + LambdatestNextGPT Driver + BrowserStack

Last updated 3 months ago