Search in sources :

Example 1 with SauceREST

use of com.saucelabs.saucerest.SauceREST in project activityinfo by bedatadriven.

the class SauceReporter method finished.

@Override
public void finished(Scenario scenario) {
    String sessionId = session.getSessionId().toString();
    try {
        SauceREST sauceClient = sauce.getRestClient();
        Map<String, Object> updates = new HashMap<>();
        updates.put("passed", !scenario.isFailed());
        updates.put("name", scenario.getName());
        Utils.addBuildNumberToUpdate(updates);
        sauceClient.updateJobInfo(sessionId, updates);
        String jobName = System.getenv("JOB_NAME");
        if (jobName != null) {
            scenario.write(String.format("SauceOnDemandSessionID=%s job-name=%s\n", sessionId, jobName));
        }
    } catch (Exception e) {
        System.out.println("Failed to update sauce job status: " + e.getMessage());
    }
    // Add URL of Job to Cucumber output
    scenario.write(String.format("<a href=\"https://saucelabs.com/tests/%s\">Sauce Job Page</a>\n", sessionId));
}
Also used : HashMap(java.util.HashMap) SauceREST(com.saucelabs.saucerest.SauceREST)

Example 2 with SauceREST

use of com.saucelabs.saucerest.SauceREST in project divolte-collector by divolte.

the class SeleniumTestBase method setupSauceLabs.

private void setupSauceLabs() throws MalformedURLException {
    final String sauceUserName = Optional.ofNullable(System.getenv(SAUCE_USER_NAME_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_USER_NAME_ENV_VAR + " env var."));
    final String sauceApiKey = Optional.ofNullable(System.getenv(SAUCE_API_KEY_ENV_VAR)).orElseThrow(() -> new RuntimeException("When using 'sauce' as Selenium driver, please set the SauceLabs username " + "in the " + SAUCE_API_KEY_ENV_VAR + " env var."));
    final String sauceHost = Optional.ofNullable(System.getenv(SAUCE_HOST_ENV_VAR)).orElse("localhost");
    final int saucePort = Optional.ofNullable(System.getenv(SAUCE_PORT_ENV_VAR)).map(Ints::tryParse).orElse(4445);
    final DesiredCapabilities caps = capabilities.get();
    // Note: getMethodName() is misleading. It's really the formatted name from the @Parameters annotation.
    caps.setCapability("name", String.format("%s: %s", getClass().getSimpleName(), testName.getMethodName()));
    caps.setCapability("public", "team");
    caps.setCapability("videoUploadOnPass", false);
    final RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(String.format("http://%s:%s@%s:%d/wd/hub", sauceUserName, sauceApiKey, sauceHost, saucePort)), caps);
    final String sauceJobId = remoteDriver.getSessionId().toString();
    final SauceREST sauce = new SauceREST(sauceUserName, sauceApiKey);
    driver = remoteDriver;
    testResultHook = Optional.of(result -> {
        switch(result) {
            case Passed:
                sauce.jobPassed(sauceJobId);
                break;
            case Skipped:
                sauce.deleteJob(sauceJobId);
                break;
            case Failed:
                sauce.jobFailed(sauceJobId);
        }
    });
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Statement(org.junit.runners.model.Statement) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) java.util(java.util) URL(java.net.URL) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) LoggerFactory(org.slf4j.LoggerFactory) Supplier(java.util.function.Supplier) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ImmutableList(com.google.common.collect.ImmutableList) Nullable(javax.annotation.Nullable) BrowserLists(io.divolte.server.BrowserLists) AssumptionViolatedException(org.junit.AssumptionViolatedException) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Parameter(org.junit.runners.Parameterized.Parameter) Description(org.junit.runner.Description) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Instant(java.time.Instant) Ints(com.google.common.primitives.Ints) SauceREST(com.saucelabs.saucerest.SauceREST) Collectors(java.util.stream.Collectors) TestServer(io.divolte.server.ServerTestUtils.TestServer) Consumer(java.util.function.Consumer) org.junit.rules(org.junit.rules) Rule(org.junit.Rule) Preconditions(com.google.common.base.Preconditions) Logs(org.openqa.selenium.logging.Logs) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) SauceREST(com.saucelabs.saucerest.SauceREST) URL(java.net.URL)

Aggregations

SauceREST (com.saucelabs.saucerest.SauceREST)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 Ints (com.google.common.primitives.Ints)1 BrowserLists (io.divolte.server.BrowserLists)1 TestServer (io.divolte.server.ServerTestUtils.TestServer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Instant (java.time.Instant)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 Rule (org.junit.Rule)1 org.junit.rules (org.junit.rules)1 Description (org.junit.runner.Description)1