Last active
October 1, 2019 20:22
-
-
Save sauceaaron/7cb2a4a31d01df54bbe0356bd079175e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.testng.Assert; | |
| import org.openqa.selenium.chrome.ChromeOptions; | |
| import org.openqa.selenium.remote.RemoteWebDriver; | |
| import org.openqa.selenium.MutableCapabilities; | |
| import java.net.URL; | |
| public class SeleniumNewVersionTest | |
| { | |
| public static void main(String[] args) throws Exception | |
| { | |
| String username = System.getenv("SAUCE_USERNAME"); | |
| String accessKey = System.getenv("SAUCE_ACCESS_KEY"); | |
| System.out.println("\nSetting Capabilities."); | |
| ChromeOptions chromeOpts = new ChromeOptions(); | |
| chromeOpts.setExperimentalOption("w3c", true); | |
| MutableCapabilities sauceOpts = new MutableCapabilities(); | |
| sauceOpts.setCapability("seleniumVersion", "3.11.0"); | |
| sauceOpts.setCapability("user", username); | |
| sauceOpts.setCapability("accessKey", accessKey); | |
| sauceOpts.setCapability("name", "Selenium_4_test"); | |
| // DesiredCapabilities caps = new DesiredCapabilities(); | |
| MutableCapabilities caps = new MutableCapabilities(); | |
| caps.setCapability(ChromeOptions.CAPABILITY, chromeOpts); | |
| caps.setCapability("platformName", "Windows 8.1"); | |
| caps.setCapability("browserVersion", "77.0"); | |
| caps.setCapability("sauce:options", sauceOpts); | |
| caps.setCapability("goog:chromeOptions", chromeOpts); | |
| String sauceUrl = "https://"+username+":"+accessKey+"@ondemand.saucelabs.com/wd/hub"; | |
| URL url = new URL(sauceUrl); | |
| RemoteWebDriver driver = new RemoteWebDriver(url, caps); | |
| try | |
| { | |
| System.out.println("\nStarting driver get title test."); | |
| driver.navigate().to("https://www.saucedemo.com"); | |
| String getTitle = driver.getTitle(); | |
| Assert.assertEquals(getTitle, "Swag Labs"); | |
| if (getTitle.contentEquals("Swag Labs")) | |
| { | |
| System.out.println("\nGet Title Test Passed."); | |
| } | |
| else | |
| { | |
| System.out.println("\nGet Title Test Failed."); | |
| } | |
| driver.quit(); | |
| } | |
| catch (Exception ex) | |
| { | |
| System.out.println("\nCan't execute script on SauceLabs: " +ex); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment