-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathSeleniumTest.java
47 lines (38 loc) · 1.57 KB
/
SeleniumTest.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
package com.saucedemo.selenium.testng.demo;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
/** Example of running a TestNG test without using Sauce Bindings. */
public class SeleniumTest {
protected RemoteWebDriver driver;
@BeforeMethod
public void setup(Method method) throws MalformedURLException {
MutableCapabilities sauceOptions = new MutableCapabilities();
sauceOptions.setCapability("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.setCapability("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
sauceOptions.setCapability("name", method.getName());
sauceOptions.setCapability("browserVersion", "latest");
ChromeOptions options = new ChromeOptions();
options.setCapability("sauce:options", sauceOptions);
URL url = new URL("https://ondemand.us-west-1.saucelabs.com/wd/hub");
driver = new RemoteWebDriver(url, options);
}
@Test
public void correctTitle() {
driver.navigate().to("https://www.saucedemo.com");
Assert.assertEquals("Swag Labs", driver.getTitle());
}
@AfterMethod
public void teardown(ITestResult result) {
String status = result.isSuccess() ? "passed" : "failed";
driver.executeScript("sauce:job-result=" + status);
}
}