/
SauceRESTTest.java
executable file
·76 lines (60 loc) · 2.67 KB
/
SauceRESTTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.dynacrongroup.webtest.webdriverbase;
import com.dynacrongroup.webtest.ParallelRunner;
import com.dynacrongroup.webtest.SauceLabsCredentials;
import com.dynacrongroup.webtest.WebDriverBase;
import com.dynacrongroup.webtest.WebDriverUtilities;
import com.dynacrongroup.webtest.sauce.SauceREST;
import com.dynacrongroup.webtest.util.Path;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
/**
* Sample WebDriver test case showing how to use the rest interface.
*
*/
@RunWith(ParallelRunner.class)
public class SauceRESTTest extends WebDriverBase {
Path p = new Path("www.dynacrongroup.com", 80);
private static final Logger LOG = LoggerFactory.getLogger(SauceRESTTest.class);
public SauceRESTTest(String browser, String browserVersion) {
super(browser, browserVersion);
}
@Before
public void loadPage() {
assumeTrue(this.getTargetWebBrowser().isRemote());
if (!driver.getTitle().startsWith("Webtest")) {
driver.get(p._("/webtest.html"));
}
}
/**
* Verify that a test can be stopped via the rest interface, using status from rest interface.
* @throws Exception
*/
@Test
@Ignore("Calling this manually causes trouble for WebDriver lifecycle.")
public void stopJobTest() throws Exception {
getLogger().info("Starting test [{}]", name.getMethodName());
assertTrue(WebDriverUtilities.isElementPresent(driver, By.tagName("h2")));
LOG.info("Initial status: [{}] ", new SauceREST(SauceLabsCredentials.getUser(), SauceLabsCredentials.getKey()).getJobStatus(this.getJobId()).toString());
LOG.info("Stop request result: [{}]", new SauceREST(SauceLabsCredentials.getUser(), SauceLabsCredentials.getKey()).stopJob(this.getJobId()).toString());
JSONObject status = new SauceREST(SauceLabsCredentials.getUser(), SauceLabsCredentials.getKey()).getJobStatus(this.getJobId());
assertThat((String) status.get("status"), equalTo("complete"));
}
@Test
public void jobsList() {
LOG.info("Starting [{}]", name.getMethodName());
JSONArray jobsList = new SauceREST(SauceLabsCredentials.getUser(), SauceLabsCredentials.getKey()).getAllJobs();
assertThat(jobsList.toString(), containsString(this.getJobId()));
}
}