本文整理汇总了Java中com.saucelabs.saucerest.SauceREST类的典型用法代码示例。如果您正苦于以下问题:Java SauceREST类的具体用法?Java SauceREST怎么用?Java SauceREST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SauceREST类属于com.saucelabs.saucerest包,在下文中一共展示了SauceREST类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tearDown
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
/**
* <p>
* Saucelabs tearDown, flag the tests as passed or failed.
* </p><p>
* Uses the SauceREST API to register a test as passed or failed. {@see #SAUCE_REST_API_DELAY_MS}
* </p>
*
* @param passed true if passed, falsed if failed, as a boolean
* @param sessionId saucelabs test session id, as a String
* @throws Exception
*/
public void tearDown(boolean passed, String sessionId, String className, String testName) throws Exception {
if (sessionId != null && System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) != null) { // dup guard so WebDriverUtils doesn't have to be used
SauceREST client = new SauceREST(System.getProperty(SauceLabsWebDriverHelper.SAUCE_USER_PROPERTY),
System.getProperty(SauceLabsWebDriverHelper.SAUCE_KEY_PROPERTY));
/* Using a map of udpates:
* (http://saucelabs.com/docs/sauce-ondemand#alternative-annotation-methods)
*/
Map<String, Object> updates = new HashMap<String, Object>();
updates.put("passed", passed);
updates.put("build", System.getProperty(SAUCE_BUILD_PROPERTY, "unknown"));
client.updateJobInfo(sessionId, updates);
if (passed) {
client.jobPassed(sessionId);
} else {
client.jobFailed(sessionId);
}
// give the client message a chance to get processed on saucelabs side
Thread.sleep(Integer.parseInt(System.getProperty(SAUCE_REST_API_DELAY_MS, "5000")));
downloadResults(className, testName);
}
}
示例2: configure
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
@Override
protected void configure() {
Properties properties = new Properties();
bind(SauceCommandLineArguments.class).toInstance(SauceCommandLineArguments.ARGUMENTS);
Path propertiesPath = Paths.get(SauceCommandLineArguments.ARGUMENTS.conf());
if (Files.exists(propertiesPath)) {
try {
properties.load(new FileInputStream(propertiesPath.toFile()));
} catch (IOException e) {
throw new IllegalStateException("Failed to load properties file " + propertiesPath, e);
}
} else {
throw new IllegalArgumentException("Properties file does not exist " + propertiesPath);
}
String sauceKey = properties.getProperty(PropertiesModule.SAUCE_KEY);
String sauceUser = properties.getProperty(PropertiesModule.SAUCE_USER);
Preconditions.checkArgument(!Strings.isNullOrEmpty(sauceKey), String.format("Set %s in the properties file", PropertiesModule.SAUCE_KEY));
Preconditions.checkArgument(!Strings.isNullOrEmpty(sauceUser), String.format("Set %s in the properties file", PropertiesModule.SAUCE_USER));
bind(SauceREST.class).toInstance(new SauceREST(properties.getProperty(PropertiesModule.SAUCE_USER), properties.getProperty(PropertiesModule.SAUCE_KEY)));
}
示例3: finishTest
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
public static void finishTest(WebDriver driver){
if (System.getenv().get("TRAVIS_JOB_NUMBER") != null) {
SauceREST sauceRest = new SauceREST(System.getenv().get("SAUCE_USERNAME"), System.getenv().get("SAUCE_ACCESS_KEY"));
sauceRest.jobPassed((((RemoteWebDriver) driver).getSessionId()).toString());
}
driver.close();
driver.quit();
}
示例4: i_close_the_browse
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
@Then("^I close the browser$")
public void i_close_the_browse() throws Throwable {
if (StepsUtil.getSauceUser() != null) {
SauceREST r = new SauceREST(StepsUtil.getSauceUser(),StepsUtil.getSaucePassword());
String sessionId = (((RemoteWebDriver) SeleniumUtils.driver).getSessionId()).toString();
r.jobPassed(sessionId);
}
SeleniumUtils.driver.quit();
}
示例5: addTestName
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
public static void addTestName(String sessionID, String testName)
{
SauceREST r = connectToSauceREST();
Map<String, Object> updates = new HashMap<>();
updates.put("name", testName);
r.updateJobInfo(sessionID, updates);
}
示例6: main
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
/**
* Should receive the path of the file to upload and the conf with the properties file with the credentials.
*
* @param args the command line arguments.
* @throws Exception if there was an error.
*/
public static void main(String[] args) throws Exception {
SauceCommandLineArguments arguments = SauceCommandLineArguments.initialize(args);
checkArguments(arguments);
List<Module> modules = Lists.newArrayList(new SauceLabsModule());
Injector injector = Guice.createInjector(modules);
SauceREST sauceREST = injector.getInstance(SauceREST.class);
long start = System.currentTimeMillis();
LOG.info(String.format("Uploading file %s to SauceLabs, overwriting %s",
arguments.file().getFileName().toString(), arguments.overwrite()));
sauceREST.uploadFile(arguments.file().toFile(), arguments.file().getFileName().toString(), arguments.overwrite());
LOG.info(String.format("Finishing uploading file %s in %s", arguments.file().getFileName().toString(),
Util.TO_PRETTY_FORMAT.apply(System.currentTimeMillis() - start)));
}
示例7: storeBuildNumberInSauce
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
/**
* Invokes the Sauce REST API to store the TeamCity build number and pass/fail status within
* Sauce.
* @param build
* @param sessionId
*/
private void storeBuildNumberInSauce(SRunningBuild build, String sessionId) {
Collection<SBuildFeatureDescriptor> features = build.getBuildType().getBuildFeatures();
if (features.isEmpty()) return;
for (SBuildFeatureDescriptor feature : features) {
if (feature.getType().equals("sauce")) {
SauceREST sauceREST = new SauceREST(getUsername(feature), getAccessKey(feature));
Map<String, Object> updates = new HashMap<String, Object>();
try {
String json = sauceREST.getJobInfo(sessionId);
JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
String buildNumber = build.getBuildTypeExternalId() + build.getBuildNumber();
logger.info("Setting build number " + buildNumber + " for job " + sessionId + " user: " + getUsername(feature));
updates.put("build", buildNumber);
if (jsonObject.get("passed") == null || jsonObject.get("passed").equals("")) {
if (build.getStatusDescriptor().getStatus().isSuccessful()) {
updates.put("passed", Boolean.TRUE.toString());
} else if (build.getStatusDescriptor().getStatus().isFailed()) {
updates.put("passed", Boolean.FALSE.toString());
}
}
sauceREST.updateJobInfo(sessionId, updates);
} catch (org.json.simple.parser.ParseException e) {
logger.error("Failed to parse JSON for session id: " + sessionId + " user: " + getUsername(feature), e);
}
}
}
}
示例8: flagTestPassed
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
public static void flagTestPassed(String sessionID)
{
SauceREST r = connectToSauceREST();
r.jobPassed(sessionID);
}
示例9: flagTestFailed
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
public static void flagTestFailed(String sessionID)
{
SauceREST r = connectToSauceREST();
r.jobFailed(sessionID);
}
示例10: connectToSauceREST
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
private static SauceREST connectToSauceREST()
{
return new SauceREST(System.getProperty("sauceUsername"), System.getProperty("sauceAccessKey"));
}
示例11: configure
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
@Override
protected void configure() {
// Loads the default properties.
Properties properties = new Properties();
defaultProperties.entrySet()
.stream()
.forEach(entry -> properties.setProperty(entry.getKey(), entry.getValue()));
String path = TestRunnerConfig.ARGUMENTS == null ? DEFAULT_CONFIG : TestRunnerConfig.ARGUMENTS.conf();
Path propertiesPath = Paths.get(path);
// Loads the properties set in the properties file.
if (Files.exists(propertiesPath)) {
try {
properties.load(new FileInputStream(propertiesPath.toFile()));
} catch (IOException e) {
throw new IllegalStateException("Failed to load properties file " + propertiesPath, e);
}
} else {
throw new IllegalArgumentException("Properties file does not exist " + propertiesPath);
}
// To load the capabilities from properties file.
if (TestRunnerConfig.ARGUMENTS == null && properties.get(CAPABILITIES) != null) {
TestRunnerConfig.initialize(properties);
}
if (TestRunnerConfig.ARGUMENTS == null) {
throw new IllegalStateException("Capabilities were not loaded. Please set on properties file or command line args.");
}
if (TestRunnerConfig.ARGUMENTS.sauce()) {
setSauceProperties(properties);
} else {
properties.setProperty(PropertiesModule.REMOTE_ADDRESS, properties.getProperty(PropertiesModule.LOCAL_ADDRESS));
}
// This will override the properties set in the property file, with the properties sent in the extra parameters.
if (TestRunnerConfig.ARGUMENTS.extra() != null
&& !TestRunnerConfig.ARGUMENTS.extra().isEmpty()) {
properties.putAll(TestRunnerConfig.ARGUMENTS.extra());
}
Names.bindProperties(binder(), properties);
bind(DesiredCapabilities.class).toInstance(TestRunnerConfig.ARGUMENTS.capabilities());
bind(String.class)
.annotatedWith(Names.named(PropertiesModule.UNIQUE_ID))
.toInstance(ID);
// Always set SauceRest, even with empty user key, so Guice does not complain.
bind(SauceREST.class).toInstance(new SauceREST(properties.getProperty(PropertiesModule.SAUCE_USER), properties.getProperty(PropertiesModule.SAUCE_KEY)));
}
示例12: SauceLabsIntegration
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
@Inject
public SauceLabsIntegration(SauceREST sauceREST, TestRunnerConfig arguments) {
this.sauceRest = Preconditions.checkNotNull(sauceREST);
this.arguments = Preconditions.checkNotNull(arguments);
}
示例13: retrieveJobIdsFromSauce
import com.saucelabs.saucerest.SauceREST; //导入依赖的package包/类
/**
* Retrieve the list of Sauce jobs recorded against the TeamCity build.
*
* @param build
* @return
* @throws IOException
* @throws JSONException
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
*/
public List<JobInformation> retrieveJobIdsFromSauce(SBuild build) throws IOException, JSONException, InvalidKeyException, NoSuchAlgorithmException {
//invoke Sauce Rest API to find plan results with those values
List<JobInformation> jobInformation = new ArrayList<JobInformation>();
SBuildFeatureDescriptor sauceBuildFeature = getSauceBuildFeature(build);
if (sauceBuildFeature == null) {
return null;
}
String username = sauceBuildFeature.getParameters().get(Constants.SAUCE_USER_ID_KEY);
String accessKey = sauceBuildFeature.getParameters().get(Constants.SAUCE_PLUGIN_ACCESS_KEY);
String buildNumber = build.getBuildTypeExternalId() + build.getBuildNumber();
SauceREST sauceREST = new SauceREST(username, accessKey);
logger.info("Retrieving Sauce jobs for " + buildNumber + " user: " + username);
String jsonResponse = sauceREST.retrieveResults(new URL(String.format(JOB_DETAILS_URL, username, buildNumber)));
JSONObject job = new JSONObject(jsonResponse);
JSONArray jobResults = job.getJSONArray("jobs");
if (jobResults.length() == 0) {
//try query using the build number
logger.info("Retrieving Sauce jobs for " + build.getBuildNumber() + " user: " + username);
jsonResponse = sauceREST.retrieveResults(new URL(String.format(JOB_DETAILS_URL, username, build.getBuildNumber())));
job = new JSONObject(jsonResponse);
jobResults = job.getJSONArray("jobs");
}
for (int i = 0; i < jobResults.length(); i++) {
//check custom data to find job that was for build
JSONObject jobData = jobResults.getJSONObject(i);
String jobId = jobData.getString("id");
JobInformation information = new JobInformation(jobId, calcHMAC(username, accessKey, jobId));
String status = jobData.getString("passed");
if (status.equals("null")) {
status = "not set";
}
information.setStatus(status);
information.setName(jobData.getString("name"));
jobInformation.add(information);
}
//the list of results retrieved from the Sauce REST API is last-first, so reverse the list
Collections.reverse(jobInformation);
return jobInformation;
}