通过Jenkins Sauce on Demand更新SauceLabs上的作业状态

时间:2016-03-25 00:34:50

标签: jenkins cucumber saucelabs

我正在使用Cucumber和SauceLabs使用插件Sauce on Demand运行Jenkins测试。

与Sauce on Demand的集成工作正常,但我无法在SauceLabs上设置通过/失败状态。

WebDriver Instantiation

    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(System.getenv("SELENIUM_BROWSER"));
    desiredCapabilities.setVersion(System.getenv("SELENIUM_VERSION"));
    desiredCapabilities.setCapability(CapabilityType.PLATFORM,System.getenv("SELENIUM_PLATFORM"));

    desiredCapabilities.setCapability("build", System.getenv("JOB_NAME") + "_" + System.getenv("BUILD_NUMBER"));
    desiredCapabilities.setCapability("name", jobName);
    WebDriver driver = new RemoteWebDriver(
            new URL("http://"+System.getenv("SAUCE_USERNAME")+":"+System.getenv("SAUCE_ACCESS_KEY")+"@ondemand.saucelabs.com:80/wd/hub"),
            desiredCapabilities);

在日志上打印SessionID和JobName

    String message = String.format("SauceOnDemandSessionID=%1$s job-name=%2$s",
            (((RemoteWebDriver) driver).getSessionId()).toString(), jobName);
    System.out.println(message);

黄瓜跑步者类和日志配置

@RunWith(Cucumber.class)
@CucumberOptions(
    glue = "abc",
    features = "classpath:abc/Login.feature",
    format = "junit:target/surefire-reports/Login.xml")
public class LoginCucumberTest {

}

Jenkins配置

Jenkins configuration

显示测试失败的构建结果

Build result showing the test failed

构建日志



Started by user Eduardo Marques
Building in workspace /var/lib/jenkins/jobs/abc/workspace
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url ssh://git@git.sofist.com.br/automatizacao-abc.git # timeout=10
Fetching upstream changes from ssh://git@git.sofist.com.br/automatizacao-abc.git
 > /usr/bin/git --version # timeout=10
using GIT_SSH to set credentials Jenkins GIT key
 > /usr/bin/git -c core.askpass=true fetch --tags --progress ssh://git@git.sofist.com.br/automatizacao-abc.git +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 896524e677f23ff0696d9c0c9deb778e9ec76120 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 896524e677f23ff0696d9c0c9deb778e9ec76120
 > /usr/bin/git rev-list e1225a75e40d7fc9ab47a3459d4c5e9ae3ee6a15 # timeout=10
Starting pre-build for Sauce Labs plugin
Starting Sauce Connect on master node using identifier: default
Launching Sauce Connect on 172.30.0.123
Sauce Connect 4.3.13 now launched for: eduardomarques
Incremented process count for eduardomarques, now 1
Finished pre-build for Sauce Labs plugin
[workspace] $ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.2.2/bin/mvn clean test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building automatizacaoabc 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ automatizacaoabc ---
[INFO] Deleting /var/lib/jenkins/jobs/abc/workspace/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ automatizacaoabc ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ automatizacaoabc ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /var/lib/jenkins/jobs/abc/workspace/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ automatizacaoabc ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ automatizacaoabc ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /var/lib/jenkins/jobs/abc/workspace/target/test-classes
[INFO] /var/lib/jenkins/jobs/abc/workspace/src/test/java/abc/LoginTest.java: /var/lib/jenkins/jobs/abc/workspace/src/test/java/abc/LoginTest.java uses or overrides a deprecated API.
[INFO] /var/lib/jenkins/jobs/abc/workspace/src/test/java/abc/LoginTest.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ automatizacaoabc ---
[INFO] Surefire report directory: /var/lib/jenkins/jobs/abc/workspace/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running abc.LoginCucumberTest
SauceOnDemandSessionID=469a6e39f1cc4042885929c26e360340 job-name=Login com usuario valido

1 Scenarios ([32m1 passed[0m)
6 Steps ([32m6 passed[0m)
0m15.918s

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 16.894 sec

Results :

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.163 s
[INFO] Finished at: 2016-03-24T23:57:12+00:00
[INFO] Final Memory: 17M/41M
[INFO] ------------------------------------------------------------------------
Starting post-build for Sauce Labs plugin
Shutting down Sauce Connect
Decremented process count for eduardomarques, now 0
Flushing Sauce Connect Input Stream
Flushing Sauce Connect Error Stream
Closing Sauce Connect process
Sauce Connect stopped for: eduardomarques
Finished post-build for Sauce Labs plugin
Recording test results
Starting Sauce Labs test publisher
Finished Sauce Labs test publisher
Finished: SUCCESS




2 个答案:

答案 0 :(得分:0)

该插件不会为您更新通过/失败状态。我已经成功地通过在我的框架中使用Sauce-Rest软件包更新了Sauce Labs Pass / Fail状态。

以下是Sauce-Rest Repo的链接:

https://github.com/saucelabs/saucerest-java

这是我的工作代码:

import com.saucelabs.saucerest.SauceREST;

    public void UpdateResults(boolean testResults) throws JSONException, ClientProtocolException, IOException {
        SauceREST saucerest = new SauceREST(USERNAME, ACCESS_KEY);
        Map<String, Object> updates = new HashMap<String, Object>();
        updates.put("passed", testResults);
        saucerest.updateJobInfo(sessionId, updates);
    }

    @After
    public void tearDown() throws Throwable {
        driver.quit();
        UpdateResults(testResults);
        System.out.println("SauceOnDemandSessionID="+ sessionId + "job-name="+ jobName);
    }

来源:

https://github.com/saucelabs-sample-test-frameworks/Java-CucumberJVM/blob/master/src/test/java/com/yourcompany/saucecucumberjvm/GuineaPigSteps.java

答案 1 :(得分:0)

您可以在钩子之后中使用以下代码行来更新ucelabs中的结果

model = tf.keras.Sequential([ tf.keras.layers.Embedding(2 ** SEQUENCE_MAX_LENGTH, 64), tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64, return_sequences=True)), tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32)), tf.keras.layers.Dense(64, activation='relu'), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(1e-4), metrics=['accuracy']) history = model.fit( TRAINING_DATA, << Doesnt work because my training data format is completely off epochs=10, validation_data=TEST_DATA, validation_steps=30 )

((JavascriptExecutor) driver).executeScript("sauce:job-result=<passed/failed>"); 方法将在cucumber-jvm中提供方案的状态。