package Checkout;
import org.testng.asserts.SoftAssert;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.UnexpectedException;
import java.util.concurrent.TimeUnit;
import org.testng.ITestResult;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class TestBaseFR {
Object verificationErrors;
private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
private ThreadLocal<String> sessionId = new ThreadLocal<String>();
SoftAssert softAssert=new SoftAssert();
public static final String BUILDTAG = System.getenv("BUILD_TAG");
// enter your saucelabs user name here
public static final String USERNAME = System.getenv("SAUCE_USERNAME");
// enter your access key here
public static final String ACCESS_KEY = System.getenv("SAUCE_ACCESS_KEY");
public static final String SauceLabURL = "http://" + USERNAME + ":" + ACCESS_KEY
+ "@ondemand.saucelabs.com:80/wd/hub";
/**
* DataProvider that explicitly sets the browser combinations to be used.
*
* @param testMethod
* @return Two dimensional array of objects with browser, version, and platform information
*/
@DataProvider(name = "hardCodedBrowsers", parallel = true)
public static Object[][] sauceBrowserDataProvider(Method testMethod) {
return new Object[][]{
new Object[]{"MicrosoftEdge", "14.14393", "Windows 10"},
new Object[]{"firefox", "49.0", "Windows 10"},
new Object[]{"internet explorer", "11.0", "Windows 7"},
new Object[]{"safari", "10.0", "OS X 10.11"},
new Object[]{"chrome", "54.0", "OS X 10.10"},
new Object[]{"firefox", "latest-1", "Windows 7"},
};
}
public WebDriver driver;
/**
* @return the {@link WebDriver} for the current thread
*/
public WebDriver getWebDriver() {
return webDriver.get();
}
/**
*
* @return the Sauce Job id for the current thread
*/
public String getSessionId() {
return sessionId.get();
}
/**
* @throws java.lang.Exception
*/
protected void CreateDriver(String browser, String version, String os, String methodName)
throws MalformedURLException, UnexpectedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.BROWSER_NAME, browser);
caps.setCapability(CapabilityType.VERSION,version);
caps.setCapability(CapabilityType.PLATFORM_NAME,os);
caps.setCapability("name",methodName);
driver = new RemoteWebDriver(new URL(SauceLabURL), caps);
if (BUILDTAG != null) {
caps.setCapability("build", BUILDTAG);
}
// Launch remote browser and set it as the current thread
webDriver.set(new RemoteWebDriver(
new URL("https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"),
caps));
// set current sessionId
String id = ((RemoteWebDriver) getWebDriver()).getSessionId().toString();
sessionId.set(id);
}
// Test Results
@AfterMethod(alwaysRun = true)
public void tearDown(ITestResult result) throws Exception {
((JavascriptExecutor) webDriver.get()).executeScript("sauce:job-result=" + (result.isSuccess() ? "passed" : "failed"));
webDriver.get().quit();
}
protected void annotate(String text) {
((JavascriptExecutor) webDriver.get()).executeScript("sauce:context=" + text);
}
}