All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xamarin.testcloud.appium.EnhancedAndroidDriver Maven / Gradle / Ivy

Go to download

Extensions for producing nice looking test reports for appium tests in Xamarin Test Cloud

The newest version!
package com.xamarin.testcloud.appium;

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.http.HttpClient;

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

public class EnhancedAndroidDriver extends io.appium.java_client.android.AndroidDriver {

    protected final EventReporter eventReporter;

    public EnhancedAndroidDriver(URL remoteAddress, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(remoteAddress, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(remoteAddress, httpClientFactory, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(service, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(service, httpClientFactory, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(builder, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(builder, httpClientFactory, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(httpClientFactory, desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    public EnhancedAndroidDriver(Capabilities desiredCapabilities, EventReporter eventReporter) {
        super(desiredCapabilities);
        this.eventReporter = eventReporter;
    }

    /**
     * Get screenshot from device. Will store a copy of the screenshot in parent working directory and in test-cloud
     * it will be inserted into test report.
     * @param outputType output format of screenshot
     * @param  output format of screenshot
     * @return screenshot
     * @throws WebDriverException if an error occurs
     * @see #label(String) for the perfered way to insert screenshots in test reports.
     */
    @Override
    public  X getScreenshotAs(OutputType outputType) throws WebDriverException {
        return DriverHelper.getScreenshotToWorkspace(execute(DriverCommand.SCREENSHOT).getValue(), outputType, path ->
                 eventReporter.reportScreenshot(path.toAbsolutePath().toString(), 0, false));
    }

    /**
     * Label a point of time in a test. Will insert a screenshot and label {@code label} into test report when running
     * in test-cloud.
     * @param label text to insert into report.
     */
    public void label(String label) {
        DriverHelper.getScreenshotToWorkspace(execute(DriverCommand.SCREENSHOT).getValue(), OutputType.FILE, path ->
                eventReporter.reportLabel(DriverHelper.sanitize(label), path.toAbsolutePath().toString(), 0, false));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy