public FormValidation doValidate( @QueryParameter String username, @QueryParameter String apiKey, @QueryParameter boolean disableStatusColumn, @QueryParameter boolean reuseSauceAuth) { try { SauceOnDemandAuthentication credential = reuseSauceAuth ? new SauceOnDemandAuthentication() : new SauceOnDemandAuthentication( username, Secret.toString(Secret.fromString(apiKey))); // we aren't interested in the results of the REST API call - just the fact that we executed // without an error is enough to verify the connection if (reuseSauceAuth && StringUtils.isBlank(credential.getUsername()) && StringUtils.isBlank(credential.getAccessKey())) { return FormValidation.error("Unable to find ~/.sauce-ondemand file"); } else { String response = new SauceREST(credential.getUsername(), credential.getAccessKey()) .retrieveResults("tunnels"); if (response != null && !response.equals("")) { return FormValidation.ok("Success"); } else { return FormValidation.error("Failed to connect to Sauce OnDemand"); } } } catch (Exception e) { return FormValidation.error(e, "Failed to connect to Sauce OnDemand"); } }
private void setupForSauceLabsTesting() throws Exception { URL url = new URL( "http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"); // DesiredCapabilities capabilities = new // DesiredCapabilities(BrowserType.SAFARI,"latest",Platform.MAC); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, browser); if (version != null) { capabilities.setCapability(CapabilityType.VERSION, version); } capabilities.setCapability(CapabilityType.PLATFORM, os); String methodName = this.name.getMethodName(); String className = this.getClass().getSimpleName(); capabilities.setCapability("name", className + "_" + methodName); this.driver = new RemoteWebDriver(url, capabilities); this.sessionId = (((RemoteWebDriver) driver).getSessionId()).toString(); }
/** * Creates a new {@link RemoteWebDriver} instance to be used to run WebDriver tests using Sauce. * * @param username the Sauce username * @param key the Sauce access key * @param os the operating system to be used * @param browser the name of the browser to be used * @param browserVersion the version of the browser to be used * @param method the test method being executed * @throws Exception thrown if any errors occur in the creation of the WebDriver instance */ @Parameters({"username", "key", "os", "browser", "browserVersion"}) @BeforeMethod public void setUp( @Optional("ivolf") String username, @Optional("90e3bb89-c21d-4885-85cf-f25494db06ff") String key, @Optional("Windows 8.1") String os, @Optional("internet explorer") String browser, @Optional("11") String browserVersion, Method method) throws Exception { if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(key)) { authentication = new SauceOnDemandAuthentication(username, key); } else { authentication = new SauceOnDemandAuthentication("ivolf", "90e3bb89-c21d-4885-85cf-f25494db06ff"); } DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(browser); capabilities.setCapability("version", browserVersion); capabilities.setCapability("platform", os); capabilities.setCapability("name", method.getName()); this.driver = new RemoteWebDriver( new URL( "http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); }
/** Run before each test * */ @Before public void setUp() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version", "1.1.0"); capabilities.setCapability("platformVersion", "7.1"); capabilities.setCapability("platformName", "ios"); capabilities.setCapability("deviceName", "iPhone Simulator"); // Set job name on Sauce Labs capabilities.setCapability("name", "Java iOS tutorial " + date); String userDir = System.getProperty("user.dir"); String localApp = "UICatalog6.1.app.zip"; if (runOnSauce) { String user = auth.getUsername(); String key = auth.getAccessKey(); // Upload app to Sauce Labs SauceREST rest = new SauceREST(user, key); rest.uploadFile(new File(userDir, localApp), localApp); capabilities.setCapability("app", "sauce-storage:" + localApp); URL sauceURL = new URL("http://" + user + ":" + key + "@ondemand.saucelabs.com:80/wd/hub"); driver = new AppiumDriver(sauceURL, capabilities); } else { String appPath = Paths.get(userDir, localApp).toAbsolutePath().toString(); capabilities.setCapability("app", appPath); driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } sessionId = driver.getSessionId().toString(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Helpers.init(driver); }
/** * To run before each test. Here we want to define the CAPABILITIES of the target device, the APK * of the application to use, etc. */ @Before public void setUp() throws Exception { /* * Step 1 : The capabilities we want to have */ final DesiredCapabilities CAPABILITIES = new DesiredCapabilities(); CAPABILITIES.setCapability("appium-version", "1.1.0"); CAPABILITIES.setCapability("platformName", "Android"); CAPABILITIES.setCapability("deviceName", "Android"); CAPABILITIES.setCapability("platformVersion", "4.3"); // Set the job name on Sauce Labs if needed CAPABILITIES.setCapability("name", "Java Android Calculator " + date); String userDir = System.getProperty("user.dir"); /* * Step 2 : Defines the APK to use, i.e. the name of the file to push on the device */ final String LOCAL_APP = "app_calculator.apk"; /* * Step 3 : The plateform of tests : cloud with Sauce or local ? */ final URL SERVER_ADDRESS; // Upload app to Sauce Labs if run on Sauce if (runOnSauce) { String user = auth.getUsername(); String key = auth.getAccessKey(); SauceREST rest = new SauceREST(user, key); rest.uploadFile(new File(userDir, LOCAL_APP), LOCAL_APP); CAPABILITIES.setCapability("app", "sauce-storage:" + LOCAL_APP); SERVER_ADDRESS = new URL("http://" + user + ":" + key + "@ondemand.saucelabs.com:80/wd/hub"); driver = new AndroidDriver(SERVER_ADDRESS, CAPABILITIES); // Starts tests on a local platform } else { String appPath = Paths.get(userDir, LOCAL_APP).toAbsolutePath().toString(); CAPABILITIES.setCapability("app", appPath); SERVER_ADDRESS = new URL("http://127.0.0.1:4723/wd/hub"); driver = new AndroidDriver(SERVER_ADDRESS, CAPABILITIES); } sessionId = driver.getSessionId().toString(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Helpers.init(driver, SERVER_ADDRESS); }
@Before public void setUp() throws Exception { DesiredCapabilities capabillities = DesiredCapabilities.firefox(); capabillities.setCapability(CapabilityType.BROWSER_NAME, browser); capabillities.setCapability(CapabilityType.VERSION, version); capabillities.setCapability(CapabilityType.PLATFORM, Platform.valueOf(os)); this.driver = new RemoteWebDriver( new URL( "http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabillities); this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString(); }
@Before public void setUp() throws Exception { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("version", "5"); capabilities.setCapability("platform", Platform.XP); this.driver = new RemoteWebDriver( new URL( "http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); driver.get("http://tutorialapp.saucelabs.com"); this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString(); }
/** * Sets up appium. You will need to either explictly set the sauce username/access key variables, * or set SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables to reference your Sauce * account details. * * @throws Exception */ @Before public void setUp() throws Exception { String sauceUserName = authentication.getUsername(); String sauceAccessKey = authentication.getAccessKey(); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformVersion", "7.1"); capabilities.setCapability("deviceName", "iPhone Simulator"); capabilities.setCapability("appiumVersion", "1.3.4"); capabilities.setCapability("app", "https://appium.s3.amazonaws.com/TestApp7.1.app.zip"); driver = new IOSDriver( new URL( MessageFormat.format( "http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", sauceUserName, sauceAccessKey)), capabilities); this.sessionId = driver.getSessionId().toString(); values = new ArrayList<Integer>(); }
public WebDriver createDriver(String browser, String version, String os, String testName) throws MalformedURLException { // DesiredCapabilities capabilities = new DesiredCapabilities(); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.BROWSER_NAME, browser); if (version != null) { capabilities.setCapability(CapabilityType.VERSION, version); } capabilities.setCapability(CapabilityType.PLATFORM, os); capabilities.setCapability("name", testName + browser + version + os); webDriver.set( new RemoteWebDriver( new URL( "http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities)); sessionId.set(((RemoteWebDriver) getWebDriver()).getSessionId().toString()); return webDriver.get(); }