use of org.openqa.selenium.remote.RemoteWebDriver in project muikku by otavanopisto.
the class AbstractUITest method createSauceWebDriver.
protected RemoteWebDriver createSauceWebDriver() throws MalformedURLException {
final DesiredCapabilities capabilities = new DesiredCapabilities();
final String seleniumVersion = System.getProperty("it.selenium.version");
final String browser = getBrowser();
final String browserVersion = getBrowserVersion();
final String browserResolution = getBrowserResolution();
final String platform = getSaucePlatform();
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.VERSION, browserVersion);
capabilities.setCapability(CapabilityType.PLATFORM, platform);
capabilities.setCapability("name", getClass().getSimpleName() + ':' + testName.getMethodName());
capabilities.setCapability("tags", Arrays.asList(String.valueOf(getTestStartTime())));
capabilities.setCapability("build", getProjectVersion());
capabilities.setCapability("video-upload-on-pass", false);
capabilities.setCapability("capture-html", true);
capabilities.setCapability("timeZone", "Universal");
capabilities.setCapability("seleniumVersion", seleniumVersion);
if (!StringUtils.isBlank(browserResolution)) {
capabilities.setCapability("screenResolution", browserResolution);
}
if (getSauceTunnelId() != null) {
capabilities.setCapability("tunnel-identifier", getSauceTunnelId());
}
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(String.format("http://%s:%s@ondemand.saucelabs.com:80/wd/hub", getSauceUsername(), getSauceAccessKey())), capabilities);
remoteWebDriver.setFileDetector(new LocalFileDetector());
return remoteWebDriver;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.
the class MobileFactory method create.
@Override
public WebDriver create(String name, DesiredCapabilities capabilities, String seleniumHost) {
if (seleniumHost == null) {
seleniumHost = Configuration.getSeleniumUrl();
}
String mobilePlatformName = Configuration.getPlatform(capabilities);
// TODO: refactor to be able to remove SpecialKeywords.CUSTOM property completely
// use comparison for custom_capabilities here to localize as possible usage of CUSTOM attribute
String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);
if (!customCapabilities.isEmpty() && (customCapabilities.toLowerCase().contains("localhost") || customCapabilities.toLowerCase().contains("browserstack") || customCapabilities.toLowerCase().contains("saucelabs"))) {
mobilePlatformName = SpecialKeywords.CUSTOM;
}
LOGGER.debug("selenium: " + seleniumHost);
RemoteWebDriver driver = null;
// if inside capabilities only singly "udid" capability then generate default one and append udid
if (isCapabilitiesEmpty(capabilities)) {
capabilities = getCapabilities(name);
} else if (capabilities.asMap().size() == 1 && capabilities.getCapability("udid") != null) {
String udid = capabilities.getCapability("udid").toString();
capabilities = getCapabilities(name);
capabilities.setCapability("udid", udid);
LOGGER.debug("Appended udid to cpabilities: " + capabilities);
}
LOGGER.debug("capabilities: " + capabilities);
try {
EventFiringAppiumCommandExecutor ce = new EventFiringAppiumCommandExecutor(new URL(seleniumHost));
if (mobilePlatformName.equalsIgnoreCase(SpecialKeywords.ANDROID)) {
driver = new AndroidDriver<AndroidElement>(ce, capabilities);
} else if (mobilePlatformName.equalsIgnoreCase(SpecialKeywords.IOS) || mobilePlatformName.equalsIgnoreCase(SpecialKeywords.TVOS)) {
driver = new IOSDriver<IOSElement>(ce, capabilities);
} else if (mobilePlatformName.equalsIgnoreCase(SpecialKeywords.CUSTOM)) {
// that's a case for custom mobile capabilities like browserstack or saucelabs
driver = new RemoteWebDriver(new URL(seleniumHost), capabilities);
} else {
throw new RuntimeException("Unsupported mobile platform: " + mobilePlatformName);
}
} catch (MalformedURLException e) {
throw new RuntimeException("Malformed selenium URL!", e);
} catch (Exception e) {
Device device = IDriverPool.nullDevice;
LOGGER.debug("STF is enabled. Debug info will be extracted from the exception.");
if (e != null) {
String debugInfo = getDebugInfo(e.getMessage());
if (!debugInfo.isEmpty()) {
String udid = getUdidFromDebugInfo(debugInfo);
String deviceName = getParamFromDebugInfo(debugInfo, "name");
device = new Device();
device.setUdid(udid);
device.setName(deviceName);
IDriverPool.registerDevice(device);
}
// there is no sense to register device in the pool as driver is not started and we don't have custom exception from MCloud
}
throw e;
}
try {
Device device = new Device(driver.getCapabilities());
IDriverPool.registerDevice(device);
// will be performed just in case uninstall_related_apps flag marked as true
device.uninstallRelatedApps();
} catch (Exception e) {
// use-case when something wrong happen during initialization and registration device information.
// the most common problem might be due to the adb connection problem
// make sure to initiate driver quit
LOGGER.error("Unable to register device!", e);
// TODO: try to handle use-case if quit in this place can hangs for minutes!
LOGGER.error("starting driver quit...");
driver.quit();
LOGGER.error("finished driver quit...");
throw e;
}
return driver;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.
the class Screenshot method capture.
/**
* Captures application screenshot, creates thumbnail and copies both images to specified screenshots location.
*
* @param driver
* instance used for capturing.
* @param isTakeScreenshot
* perform actual capture or not
* @param comment
* String
* @param fullSize
* Boolean
* @return screenshot name.
*/
private static String capture(WebDriver driver, boolean isTakeScreenshot, String comment, boolean fullSize) {
String screenName = "";
if (isTakeScreenshot) {
LOGGER.debug("Screenshot->capture starting...");
// remove all DriverListener casting to WebDriver
driver = castDriver(driver);
try {
if (!isCaptured(comment)) {
// LOGGER.debug("Unable to capture screenshot as driver seems invalid: " + comment);
return screenName;
}
// Define test screenshot root
File testScreenRootDir = ReportContext.getTestDir();
// Capture full page screenshot and resize
screenName = System.currentTimeMillis() + ".png";
String screenPath = testScreenRootDir.getAbsolutePath() + "/" + screenName;
WebDriver augmentedDriver = driver;
// hotfix to converting proxy into the valid driver
if (driver instanceof Proxy) {
try {
InvocationHandler innerProxy = Proxy.getInvocationHandler((Proxy) driver);
// "arg$2" is by default RemoteWebDriver;
// "arg$1" is EventFiringWebDriver
// wrap into try/catch to make sure we don't affect test execution
Field locatorField = innerProxy.getClass().getDeclaredField("arg$2");
locatorField.setAccessible(true);
augmentedDriver = driver = (WebDriver) locatorField.get(innerProxy);
} catch (Exception e) {
// do nothing and receive augmenting warning in the logs
}
}
if (!driver.toString().contains("AppiumNativeDriver")) {
// do not augment for Appium 1.x anymore
augmentedDriver = new DriverAugmenter().augment(driver);
}
BufferedImage screen;
// Create screenshot
if (fullSize) {
screen = takeFullScreenshot(driver, augmentedDriver);
} else {
screen = takeVisibleScreenshot(augmentedDriver);
}
if (screen == null) {
// do nothing and return empty
return "";
}
if (Configuration.getInt(Parameter.BIG_SCREEN_WIDTH) != -1 && Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT) != -1) {
resizeImg(screen, Configuration.getInt(Parameter.BIG_SCREEN_WIDTH), Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT), screenPath);
}
File screenshot = new File(screenPath);
ImageIO.write(screen, "PNG", screenshot);
com.zebrunner.agent.core.registrar.Screenshot.upload(Files.readAllBytes(screenshot.toPath()), Instant.now().toEpochMilli());
// add screenshot comment to collector
ReportContext.addScreenshotComment(screenName, comment);
} catch (NoSuchWindowException e) {
LOGGER.warn("Unable to capture screenshot due to NoSuchWindowException!");
LOGGER.debug(ERROR_STACKTRACE, e);
} catch (IOException e) {
LOGGER.warn("Unable to capture screenshot due to the I/O issues!");
LOGGER.debug(ERROR_STACKTRACE, e);
} catch (WebDriverException e) {
LOGGER.warn("Unable to capture screenshot due to the WebDriverException!");
LOGGER.debug(ERROR_STACKTRACE, e);
} catch (Exception e) {
LOGGER.warn("Unable to capture screenshot due to the Exception!");
LOGGER.debug(ERROR_STACKTRACE, e);
} finally {
LOGGER.debug("Screenshot->capture finished.");
}
}
return screenName;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.
the class Screenshot method takeFullScreenshot.
/**
* Makes fullsize screenshot using javascript (May not work properly with
* popups and active js-elements on the page)
*
* @param driver
* - webDriver.
* @param augmentedDriver
* - webDriver.
* @exception Exception can be cause by read() or getScreenshotAs() methods
*
* @return screenshot image
*/
private static BufferedImage takeFullScreenshot(WebDriver driver, WebDriver augmentedDriver) throws Exception {
Future<?> future = Executors.newSingleThreadExecutor().submit(new Callable<BufferedImage>() {
public BufferedImage call() throws IOException {
BufferedImage screenShot;
if (driver.getClass().toString().contains("windows")) {
File screenshot = ((WindowsDriver<?>) driver).getScreenshotAs(OutputType.FILE);
screenShot = ImageIO.read(screenshot);
} else if (driver.getClass().toString().contains("java_client")) {
// Mobile Native app
File screenshot = ((AppiumDriver<?>) driver).getScreenshotAs(OutputType.FILE);
screenShot = ImageIO.read(screenshot);
} else if (Configuration.getDriverType().equals(SpecialKeywords.MOBILE)) {
ru.yandex.qatools.ashot.Screenshot screenshot;
if (Configuration.getPlatform().equals("ANDROID")) {
String pixelRatio = String.valueOf(((EventFiringWebDriver) augmentedDriver).getCapabilities().getCapability("pixelRatio"));
if (!pixelRatio.equals("null")) {
float dpr = Float.parseFloat(pixelRatio);
screenshot = (new AShot()).shootingStrategy(ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_BLOCK, dpr)).takeScreenshot(augmentedDriver);
screenShot = screenshot.getImage();
} else {
screenshot = (new AShot()).shootingStrategy(ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_DPR)).takeScreenshot(augmentedDriver);
screenShot = screenshot.getImage();
}
} else {
int deviceWidth = augmentedDriver.manage().window().getSize().getWidth();
String deviceName = "";
if (augmentedDriver instanceof EventFiringWebDriver) {
deviceName = String.valueOf(((EventFiringWebDriver) augmentedDriver).getCapabilities().getCapability("deviceName"));
} else if (augmentedDriver instanceof RemoteWebDriver) {
deviceName = String.valueOf(((RemoteWebDriver) augmentedDriver).getCapabilities().getCapability("deviceName"));
}
screenshot = new AShot().shootingStrategy(getScreenshotShuttingStrategy(deviceWidth, deviceName)).takeScreenshot(augmentedDriver);
screenShot = screenshot.getImage();
}
} else {
// regular web
ru.yandex.qatools.ashot.Screenshot screenshot;
screenshot = (new AShot()).shootingStrategy(ShootingStrategies.viewportPasting(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT)).takeScreenshot(augmentedDriver);
screenShot = screenshot.getImage();
}
return screenShot;
}
});
BufferedImage screenShot = null;
// default timeout for driver quit 1/3 of explicit
long timeout = Configuration.getInt(Parameter.EXPLICIT_TIMEOUT) / 3;
try {
LOGGER.debug("starting full size screenshot capturing...");
screenShot = (BufferedImage) future.get(timeout, TimeUnit.SECONDS);
} catch (java.util.concurrent.TimeoutException e) {
String message = "Unable to capture full screenshot during " + timeout + "sec!";
LOGGER.error(message);
} catch (InterruptedException e) {
String message = "Unable to capture full screenshot during " + timeout + "sec!";
LOGGER.error(message);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
if (e.getMessage() != null && e.getMessage().contains("Driver connection refused")) {
LOGGER.error("Unable to capture full screenshot due to the driver connection refused!");
} else {
LOGGER.error("ExecutionException error detected on capture full screenshot!", e);
}
} catch (Exception e) {
// for undefined failure keep full stacktrace to handle later correctly!
LOGGER.error("Undefined error on capture full screenshot detected!", e);
} finally {
LOGGER.debug("finished full size screenshot call.");
}
return screenShot;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.
the class DesktopFactory method create.
@Override
public WebDriver create(String name, DesiredCapabilities capabilities, String seleniumHost) {
RemoteWebDriver driver = null;
if (seleniumHost == null) {
seleniumHost = Configuration.getSeleniumUrl();
}
if (isCapabilitiesEmpty(capabilities)) {
capabilities = getCapabilities(name);
}
if (staticCapabilities != null) {
LOGGER.info("Static DesiredCapabilities will be merged to basic driver capabilities");
capabilities.merge(staticCapabilities);
}
LOGGER.debug("capabilities: " + capabilities);
try {
driver = new RemoteWebDriver(new URL(seleniumHost), capabilities);
} catch (MalformedURLException e) {
throw new RuntimeException("Malformed selenium URL!", e);
}
resizeBrowserWindow(driver, capabilities);
return driver;
}
Aggregations