Вот мой класс с тестами:
package com.company;
import com.saucelabs.common.SauceOnDemandAuthentication;
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
import com.saucelabs.junit.ConcurrentParameterized;
//import com.saucelabs.junit.*;
import com.saucelabs.junit.SauceOnDemandTestWatcher;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.LinkedList;
import static org.junit.Assert.assertTrue;
/**
* Unit test for simple App.
*/
@RunWith(ConcurrentParameterized.class)
public class AppTest implements SauceOnDemandSessionIdProvider {
/*Parameters for Sauce Labs*/
/**
* Constructs a {@link SauceOnDemandAuthentication} instance using the supplied user name/access key. To use the authentication
* supplied by environment variables or from an external file, use the no-arg {@link SauceOnDemandAuthentication} constructor.
*/
public SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication("keepgo", "2aa620e9-a753-49e2-856e-f4d70be43abc");
@Rule
public SauceOnDemandTestWatcher resultReportingTestWatcher = new SauceOnDemandTestWatcher(this, authentication);
private String browser;
private String os;
private String version;
private String sessionId;
/**
* The {@link WebDriver} instance which is used to perform browser interactions with.
*/
private WebDriver driver;
/**
* Constructs a new instance of the test. The constructor requires three string parameters, which represent the operating
* system, version and browser to be used when launching a Sauce VM. The order of the parameters should be the same
* as that of the elements within the {@link #browsersStrings()} method.
*
* @param os
* @param version
* @param browser
*/
public AppTest(String os, String version, String browser) {
super();
this.os = os;
this.version = version;
this.browser = browser;
}
/**
* @return a LinkedList containing String arrays representing the browser combinations the test should be run against. The values
* in the String array are used as part of the invocation of the test constructor
*/
@ConcurrentParameterized.Parameters
public static LinkedList browsersStrings() {
LinkedList browsers = new LinkedList();
browsers.add(new String[]{"Windows 8.1", "11", "internet explorer"});
browsers.add(new String[]{"Windows 7", "11", "internet explorer"});
browsers.add(new String[]{"OSX 10.8", "6", "safari"});
browsers.add(new String[]{"OS X 10.9", "7.0", "safari"});
browsers.add(new String[]{"OS X 10.9", "44.0", "chrome"});
browsers.add(new String[]{"OS X 10.9", "43", "chrome"});
browsers.add(new String[]{"OS X 10.9", "40.0", "firefox"});
browsers.add(new String[]{"OS X 10.9", "39", "firefox"});
browsers.add(new String[]{"Windows XP", "12.12", "opera"});
browsers.add(new String[]{"Windows XP", "11.64", "opera"});
browsers.add(new String[]{"Windows XP", "40.0", "firefox"});
browsers.add(new String[]{"Windows XP", "39.0", "firefox"});
browsers.add(new String[]{"Windows XP", "44.0", "chrome"});
browsers.add(new String[]{"Windows XP", "43.0", "chrome"});
browsers.add(new String[]{"Windows XP", "8.0", "internet explorer"});
browsers.add(new String[]{"Windows XP", "7.0", "internet explorer"});
browsers.add(new String[]{"Windows 7", "12.12", "opera"});
browsers.add(new String[]{"Windows 7", "11.64", "opera"});
browsers.add(new String[]{"Windows 7", "40.0", "firefox"});
browsers.add(new String[]{"Windows 7", "39.0", "firefox"});
browsers.add(new String[]{"Windows 7", "5.1", "safari"});
browsers.add(new String[]{"Windows 7", "44.0", "chrome"});
browsers.add(new String[]{"Windows 7", "43.0", "chrome"});
browsers.add(new String[]{"Windows 7", "11.0", "internet explorer"});
browsers.add(new String[]{"Windows 7", "10.0", "internet explorer"});
return browsers;
}
/**
* Constructs a new {@link RemoteWebDriver} instance which is configured to use the capabilities defined by the {@link #browser},
* {@link #version} and {@link #os} instance variables, and which is configured to run against ondemand.saucelabs.com, using
* the username and access key populated by the {@link #authentication} instance.
*
* @throws Exception if an error occurs during the creation of the {@link RemoteWebDriver} instance.
*/
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
if (version != null) {
capabilities.setCapability(CapabilityType.VERSION, version);
}
capabilities.setCapability(CapabilityType.PLATFORM, os);
capabilities.setCapability("name", "Sauce Sample Test");
this.driver = new RemoteWebDriver(
new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"),
capabilities);
this.sessionId = (((RemoteWebDriver) driver).getSessionId()).toString();
}
/**
* Runs a simple test verifying the title of the keepgo.com .
* @throws Exception
*/
/***************/////////////////////////************/
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*/
/**
* Runs a simple test verifying the title of the amazon.com homepage.
* @throws Exception
*/
@org.junit.Test
public void testApp() {
driver.get("http://www.keepgo.com/pages/landing2");
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[1]/h1")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[1]/h2")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[1]/h2")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/h1[1]")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[1]/p")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[2]/p")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[3]/p")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[4]/p")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[2]")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[3]/div[4]")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[4]/div[1]")));
assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div[4]/div[1]")));
driver.findElement(By.xpath("/html/body/div[3]/div[1]/div[4]/div[2]/a[2]/div")).click(); // click on the button "Learn More " under "Lifetime Data SIM Card" field
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[1]/div[1]/div[1]/div/div[2]/img")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[1]/div[1]/a[1]")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[1]/div[1]/a[2]")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/h1")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[2]/div[1]/div/div[2]/form[2]/input[2]")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[2]/div[1]/div/div[2]/form[1]/input[2]")));
// assertTrue(isElementPresent(By.className("image-colection")));
// assertTrue(isElementPresent(By.className("row")));
// assertTrue(isElementPresent(By.className("price-box")));
// assertTrue(isElementPresent(By.className("link-to-reviews")));
// assertTrue(isElementPresent(By.className("description")));
//
// ((JavascriptExecutor) driver).executeScript("scroll(0,500)");
//
// assertTrue(isElementPresent(By.className("coverage")));
// assertTrue(isElementPresent(By.xpath("clearfix")));
//
// driver.findElement(By.className("yotpo-default-button yotpo-icon-btn pull-right yotpo-hidden-mobile write-button write-review-button")).click(); // write a review
// driver.findElement(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[3]/div/div/div[2]/div/div[2]/div/div[1]/input")).sendKeys("Sample"); // title
// driver.findElement(By.xpath("y-input yotpo-text-box")).sendKeys("Sample"); // put smth into the review field
// driver.findElement(By.xpath("/html/body/div[3]/div[1]/div/div/div[1]/div[3]/div/div/div[2]/div/input")).click(); // click on the Post button
driver.quit();
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
/**
*
* @return the value of the Sauce Job id.
*/
@Override
public String getSessionId() {
return sessionId;
}
}