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

com.epam.jdi.uitests.web.selenium.driver.SauceLabRunner Maven / Gradle / Ivy

There is a newer version: 1.1.34
Show newest version
package com.epam.jdi.uitests.web.selenium.driver;
/*
 * Copyright 2004-2016 EPAM Systems
 *
 * This file is part of JDI project.
 *
 * JDI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JDI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDI. If not, see .
 */


import com.saucelabs.common.SauceOnDemandAuthentication;
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
import com.saucelabs.junit.SauceOnDemandTestWatcher;
import org.junit.Rule;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;

import static com.epam.jdi.uitests.core.settings.JDISettings.asserter;
import static com.epam.jdi.uitests.core.settings.JDISettings.exception;
import static java.lang.System.getenv;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM;

/**
 * Created by Roman_Iovlev on 8/4/2015.
 */
public class SauceLabRunner implements SauceOnDemandSessionIdProvider {
    public static SauceOnDemandAuthentication authentication =
            new SauceOnDemandAuthentication(getenv("SAUCE_USER_NAME"), getenv("SAUCE_API_KEY"));
    private static String sessionId;
    @Rule
    public SauceOnDemandTestWatcher resultReportingTestWatcher = new SauceOnDemandTestWatcher(
            this, authentication);

    public static void setSauceSessionID(RemoteWebDriver remoteDriver) {
        sessionId = remoteDriver.getSessionId().toString();
    }

    public static DesiredCapabilities getSauceDesiredCapabilities(DriverTypes driverType) {
        DesiredCapabilities capabilities;
        switch (driverType) {
            case CHROME:
                capabilities = DesiredCapabilities.chrome(); break;
            case FIREFOX:
                capabilities = DesiredCapabilities.firefox(); break;
            case IE:
                capabilities = DesiredCapabilities.internetExplorer();  break;
            default: throw exception("Wrong driver type: " + driverType);
        }
        capabilities.setBrowserName(getenv("SELENIUM_BROWSER"));
        capabilities.setVersion(getenv("SELENIUM_VERSION"));
        capabilities.setCapability(PLATFORM, getenv("SELENIUM_PLATFORM"));
        return capabilities;
    }

    public static URL getSauceUrl() {
        return asserter.silent(() -> new URL("http://"
                + authentication.getUsername() + ":"
                + authentication.getAccessKey()
                + "@ondemand.saucelabs.com:80/wd/hub"));
    }

    public String getSessionId() {
        return sessionId;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy