如何在Saucelabs中正确使用RemoteWebDriver?

时间:2017-03-01 13:23:44

标签: selenium saucelabs

我正在尝试创建一个RemoteWebDriver,以便我可以提交一个文件作为我测试的一部分。但是,我遇到了以下错误:

SauceOnDemandSessionID=null job-name=bulkTest
Mar 01, 2017 12:48:09 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Mar 01, 2017 12:48:09 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Mar 01, 2017 12:48:09 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Mar 01, 2017 12:48:10 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
Mar 01, 2017 12:48:10 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
Mar 01, 2017 12:48:10 PM com.saucelabs.saucerest.SauceREST closeInputStream
WARNING: Error closing result stream
java.io.FileNotFoundException: https://saucelabs.com/rest/v1/tsew/jobs/null
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at com.saucelabs.saucerest.SauceREST.closeInputStream(SauceREST.java:442)
    at com.saucelabs.saucerest.SauceREST.updateJobInfo(SauceREST.java:410)
    at com.saucelabs.testng.SauceOnDemandTestListener.markJobStatus(SauceOnDemandTestListener.java:115)
    at com.saucelabs.testng.SauceOnDemandTestListener.onTestFailure(SauceOnDemandTestListener.java:102)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1691)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1675)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1183)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我的测试代码是:

package uk.gov.ons.addressindextest.Tests;

import uk.gov.ons.addressindextest.Pages.AddressIndexBulk;
import org.openqa.selenium.By;
import org.openqa.selenium.InvalidElementStateException;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.UnexpectedException;
import java.util.concurrent.TimeUnit;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;

public class AddressIndexTestBulkTest extends AddressIndexTestBase {

    /**
     * Runs a simple test verifying the search input is functional.
     * @throws InvalidElementStateException
     */
    @org.testng.annotations.Test(dataProvider = "hardCodedBrowsers")
    public void bulkTest(String browser, String version, String os, Method method)
            throws MalformedURLException, InvalidElementStateException, UnexpectedException {

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        //capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
        capabilities.setCapability("version", "7");
        capabilities.setCapability("platform", Platform.XP);
        RemoteWebDriver driver = new RemoteWebDriver(new URL("http://addressindex-ui.cfapps.io/bulkAddresses:80/"), capabilities);
        driver.setFileDetector(new LocalFileDetector());

        // initialize page object
        AddressIndexBulk gpage = PageFactory.initElements(driver, AddressIndexBulk.class);
        gpage.visitPage();
        gpage.submitBuik();

        //WebElement myDynamicElement = (new WebDriverWait(driver, 10))
          //    .until(ExpectedConditions.presenceOfElementLocated(By.className("green")));
        //assertThat(myDynamicElement.getText(), containsString("found"));
    }
}

我的页面描述是:

package uk.gov.ons.addressindextest.Pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class AddressIndexBulk extends PageBase {

    public AddressIndexBulk(WebDriver driver) {
        this.driver = driver;
    }

    public void visitPage() {
        driver.get("http://addressindex-ui.cfapps.io/bulkAddresses");
    }

    public String title = "Address index demo - Find an address";

    public static String getTitle(WebDriver driver) {
        return driver.getTitle();
    }

    @FindBy(name = "file")
    private WebElement fileButton;

    @FindBy(xpath = "//input[@type='submit'")
    private WebElement uploadButton;

    @FindBy(className = "green")
    private WebElement resultsSpan;

    public void submitBuik() {
        fileButton.clear();
        fileButton.sendKeys("addresses.csv");
        clickButton(this.uploadButton);
    }

    public String getResultsText() {
        return this.resultsSpan.getText();
    }
}

除了我想上传文件并获得提交结果的批量测试之外,我的所有其他测试都运行良好。您可以在以下位置查看我的回购: https://github.com/ONSdigital/address-index-api-tests

谢谢, 人

0 个答案:

没有答案