How to use getCapabilities method of com.qaprosoft.carina.core.foundation.webdriver.device.Device class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.device.Device.getCapabilities

Source:MobileFactory.java Github

copy

Full Screen

...72 }73 LOGGER.debug("selenium: " + seleniumHost);74 RemoteWebDriver driver = null;75 if (isCapabilitiesEmpty(capabilities)) {76 capabilities = getCapabilities(name, device);77 }78 try {79 if (driverType.equalsIgnoreCase(SpecialKeywords.MOBILE)) {80 EventFiringAppiumCommandExecutor ce = new EventFiringAppiumCommandExecutor(new URL(seleniumHost));81 if (mobilePlatformName.toLowerCase().equalsIgnoreCase(SpecialKeywords.ANDROID)) {82 if (isVideoEnabled()) {83 84 final String videoName = UUID.randomUUID().toString();85 86 AndroidStartScreenRecordingOptions o1 = new AndroidStartScreenRecordingOptions()87 .withVideoSize(R.CONFIG.get("screen_record_size"))88 .withTimeLimit(Duration.ofSeconds(R.CONFIG.getInt("screen_record_duration")))89 .withBitRate(getBitrate(VideoQuality.valueOf(R.CONFIG.get("screen_record_quality"))));90 AndroidStopScreenRecordingOptions o2 = new AndroidStopScreenRecordingOptions()91 .withUploadOptions(new ScreenRecordingUploadOptions()92 .withRemotePath(String.format(R.CONFIG.get("screen_record_ftp"), videoName))93 .withAuthCredentials(R.CONFIG.get("screen_record_user"), R.CONFIG.get("screen_record_pass")));94 ce.getListeners()95 .add(new MobileRecordingListener<AndroidStartScreenRecordingOptions, AndroidStopScreenRecordingOptions>(ce, o1, o2, initVideoArtifact(videoName)));96 }97 driver = new AndroidDriver<AndroidElement>(ce, capabilities);98 } else if (mobilePlatformName.toLowerCase().equalsIgnoreCase(SpecialKeywords.IOS)) {99 if (isVideoEnabled()) {100 101 final String videoName = UUID.randomUUID().toString();102 103 IOSStartScreenRecordingOptions o1 = new IOSStartScreenRecordingOptions()104 .withVideoQuality(VideoQuality.valueOf(R.CONFIG.get("screen_record_quality")))105 .withVideoType(VideoType.MP4)106 .withTimeLimit(Duration.ofSeconds(R.CONFIG.getInt("screen_record_duration")));107 IOSStopScreenRecordingOptions o2 = new IOSStopScreenRecordingOptions()108 .withUploadOptions(new ScreenRecordingUploadOptions()109 .withRemotePath(String.format(R.CONFIG.get("screen_record_ftp"), videoName))110 .withAuthCredentials(R.CONFIG.get("screen_record_user"), R.CONFIG.get("screen_record_pass")));111 ce.getListeners().add(new MobileRecordingListener<IOSStartScreenRecordingOptions, IOSStopScreenRecordingOptions>(ce, o1, o2, initVideoArtifact(videoName)));112 }113 driver = new IOSDriver<IOSElement>(ce, capabilities);114 } else if (mobilePlatformName.toLowerCase().equalsIgnoreCase(SpecialKeywords.CUSTOM)) {115 // that's a case for custom mobile capabilities like browserstack or saucelabs116 driver = new RemoteWebDriver(new URL(seleniumHost), capabilities);117 } else {118 throw new RuntimeException("Unsupported mobile capabilities for type: " + driverType + " platform: " + mobilePlatformName);119 }120 }121 if (device.isNull()) {122 // TODO: double check that local run with direct appium works fine123 RemoteDevice remoteDevice = getDeviceInfo(driver);124 // 3rd party solutions like browserstack or saucelabs return not null125 if (remoteDevice != null && remoteDevice.getName() != null) {126 device = new Device(remoteDevice);127 } else {128 device = new Device(driver.getCapabilities());129 }130 DevicePool.registerDevice(device);131 }132 // will be performed just in case uninstall_related_apps flag marked as true133 device.uninstallRelatedApps();134 } catch (MalformedURLException e) {135 LOGGER.error("Malformed selenium URL! " + e.getMessage(), e);136 }137 if (driver == null) {138 Assert.fail("Unable to initialize driver: " + name + "!");139 }140 return driver;141 }142 private DesiredCapabilities getCapabilities(String name, Device device) {143 DesiredCapabilities capabilities = new DesiredCapabilities();144 capabilities = new MobileCapabilies().getCapability(name);145 if (!device.isNull()) {146 capabilities.setCapability("udid", device.getUdid());147 // disable Selenium Hum <-> STF verification as device already148 // connected by this test (restart driver on the same device is invoked)149 capabilities.setCapability("STF_ENABLED", "false");150 }151 return capabilities;152 }153 /**154 * Returns device information from Grid Hub using STF service.155 * 156 * @param RemoteWebDriver157 * - driver158 * @return remote device information159 */160 private RemoteDevice getDeviceInfo(RemoteWebDriver drv) {161 RemoteDevice device = new RemoteDevice();162 try {163 @SuppressWarnings("unchecked")164 Map<String, Object> cap = (Map<String, Object>) drv.getCapabilities().getCapability(SpecialKeywords.SLOT_CAPABILITIES);165 if (cap != null && cap.containsKey("udid")) {166 // restore device information from custom slotCapabilities map167 /*168 * {deviceType=Phone, proxy_port=9000,169 * server:CONFIG_UUID=24130dde-59d4-4310-95ba-6f57b9d265c3,170 * seleniumProtocol=WebDriver, adb_port=5038,171 * vnc=wss://stage.qaprosoft.com:7410/websockify,172 * deviceName=Nokia_6_1, version=8.1.0, platform=ANDROID,173 * platformVersion=8.1.0, automationName=uiautomator2,174 * browserName=Nokia_6_1, maxInstances=1, platformName=ANDROID,175 * udid=PL2GAR9822804910}176 */177 // TODO: remove code duplicates with carina-grid DeviceInfo178 device.setName((String) cap.get("deviceName"));...

Full Screen

Full Screen

Source:DesktopFactory.java Github

copy

Full Screen

...47 if (seleniumHost == null) {48 seleniumHost = Configuration.get(Configuration.Parameter.SELENIUM_HOST);49 }50 if (isCapabilitiesEmpty(capabilities)) {51 capabilities = getCapabilities(name);52 }53 if (staticCapabilities != null) {54 LOGGER.info("Static DesiredCapabilities will be merged to basic driver capabilities");55 capabilities.merge(staticCapabilities);56 }57 try {58 59 EventFiringSeleniumCommandExecutor ce = new EventFiringSeleniumCommandExecutor(new URL(seleniumHost));60 if (isVideoEnabled()) {61 final String videoName = UUID.randomUUID().toString();62 capabilities.setCapability("videoName", videoName + ".mp4");63 capabilities.setCapability("videoFrameRate", getBitrate(VideoQuality.valueOf(R.CONFIG.get("screen_record_quality"))));64 ce.getListeners().add(new DesktopRecordingListener(initVideoArtifact(videoName)));65 }66 67 driver = new RemoteWebDriver(ce, capabilities);68 } catch (MalformedURLException e) {69 throw new RuntimeException("Unable to create desktop driver", e);70 }71 R.CONFIG.put(SpecialKeywords.ACTUAL_BROWSER_VERSION, getBrowserVersion(driver));72 return driver;73 }74 public DesiredCapabilities getCapabilities(String name) {75 String browser = Configuration.get(Parameter.BROWSER);76 if (BrowserType.FIREFOX.equalsIgnoreCase(browser)) {77 return new FirefoxCapabilities().getCapability(name);78 } else if (BrowserType.IEXPLORE.equalsIgnoreCase(browser) || BrowserType.IE.equalsIgnoreCase(browser) || browser.equalsIgnoreCase("ie")) {79 DesiredCapabilities caps = new IECapabilities().getCapability(name);80 return caps;81 } else if (BrowserType.SAFARI.equalsIgnoreCase(browser)) {82 return new SafariCapabilities().getCapability(name);83 } else if (BrowserType.CHROME.equalsIgnoreCase(browser)) {84 return new ChromeCapabilities().getCapability(name);85 } else if (BrowserType.EDGE.toLowerCase().contains(browser.toLowerCase())) {86 DesiredCapabilities caps = new EdgeCapabilities().getCapability(name);87 // forcibly override browser name to edge for support 3rd party solutions like browserstack88 caps.setBrowserName(browser);89 return caps;90 } else {91 throw new RuntimeException("Unsupported browser: " + browser);92 }93 }94 public static void addStaticCapability(String name, Object value) {95 if (staticCapabilities == null) {96 staticCapabilities = new DesiredCapabilities();97 }98 staticCapabilities.setCapability(name, value);99 }100 @Override101 public String getVncURL(WebDriver driver) {102 String vncURL = null;103 if (driver instanceof RemoteWebDriver && "true".equals(Configuration.getCapability("enableVNC"))) {104 // TODO: resolve negative case when VNC is not supported105 final RemoteWebDriver rwd = (RemoteWebDriver) driver;106 String protocol = R.CONFIG.get(vnc_protocol);107 String host = R.CONFIG.get(vnc_host);108 String port = R.CONFIG.get(vnc_port); 109 // If VNC host/port not set user them from Selenim110 if(StringUtils.isEmpty(host) || StringUtils.isEmpty(port)) {111 host = ((HttpCommandExecutor) rwd.getCommandExecutor()).getAddressOfRemoteServer().getHost();112 port = String.valueOf(((HttpCommandExecutor) rwd.getCommandExecutor()).getAddressOfRemoteServer().getPort());113 }114 vncURL = String.format(R.CONFIG.get("vnc_desktop"), protocol, host, port, rwd.getSessionId().toString());115 }116 return vncURL;117 }118 119 @Override120 protected int getBitrate(VideoQuality quality) {121 switch (quality) {122 case LOW:123 return 6;124 case MEDIUM:125 return 12;126 case HIGH:127 return 24;128 default:129 return 1;130 }131 }132 133 private String getBrowserVersion(WebDriver driver) {134 String browser_version = Configuration.get(Parameter.BROWSER_VERSION);135 try {136 Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();137 browser_version = cap.getVersion().toString();138 if (browser_version != null) {139 if (browser_version.contains(".")) {140 browser_version = StringUtils.join(StringUtils.split(browser_version, "."), ".", 0, 2);141 }142 }143 } catch (Exception e) {144 LOGGER.error("Unable to get actual browser version!", e);145 }146 return browser_version;147 }148}...

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import com.qaprosoft.carina.core.foundation.webdriver.device.Device;3import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.ios.IOSDriver;7public class getCapabilities {8 public static void main(String[] args) {9 Device device = DevicePool.getDevice();10 AppiumDriver driver = device.getDriver();11 if(driver instanceof AndroidDriver) {12 System.out.println(((AndroidDriver)driver).getCapabilities());13 }14 if(driver instanceof IOSDriver) {15 System.out.println(((IOSDriver)driver).getCapabilities());16 }17 }18}19{app=/Users/username/Desktop/CarinaDemo/src/test/resources/mobile_apps/AndroidDemoApp.apk, appPackage=com.qaprosoft.carina.demo, appActivity=com.qaprosoft.carina.demo.gui.activities.MainActivity, platformName=ANDROID, automationName=UiAutomator2, platformVersion=9, deviceName=Android, deviceUDID=emulator-5554, newCommandTimeout=300, noReset=true, fullReset=false, autoGrantPermissions=true}20{app=/Users/username/Desktop/CarinaDemo/src/test/resources/mobile_apps/iOSDemoApp.app, platformName=iOS, automationName=XCUITest, platformVersion=13.2, deviceName=iPhone 11, deviceUDID=00008020-000C0C5E1A50002E, newCommandTimeout=300, noReset=true, fullReset=false, autoGrantPermissions=true}

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;3public class 1 {4public static void main(String[] args) {5Device device = DevicePool.getDevice();6System.out.println(device.getCapabilities());7}8}9{app=com.qaprosoft.carina.demo:id/app_name, deviceName=Android, platformName=Android, platformVersion=7.0, udid=emulator-5554, newCommandTimeout=60000, appPackage=com.qaprosoft.carina.demo, appActivity=com.qaprosoft.carina.demo.gui.activities.common.SplashActivity, automationName=uiautomator2}10What is the difference between getCapabilities() and getDesiredCapabilities()?11What is the difference between getCapabilities() and getCapabilitiesAsMap()?12What is the difference between getCapabilities() and getCapabilitiesAsMap()?13What is the difference between getCapabilities() and getCapabilitiesAsMap()?14What is the difference between getCapabilities() and getCapabilitiesAsMap()?15What is the difference between getCapabilities() and getCapabilitiesAsMap()?16What is the difference between getCapabilities() and getCapabilitiesAsMap()?17getCapabilitiesAsMap() – This method is used to get the capabilities of the device

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.Map;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.testng.annotations.Test;8import com.qaprosoft.carina.core.foundation.webdriver.device.Device;9public class GetCapabilitiesDemo {10 public void testGetCapabilities() throws MalformedURLException {11 DesiredCapabilities capabilities = Device.getCapabilities("chrome");12 Map<String, Object> caps = driver.getCapabilities().asMap();13 for (String key : caps.keySet()) {14 System.out.println("Key: " + key + " Value: " + caps.get(key));15 }16 driver.quit();17 }18}19package com.qaprosoft.carina.demo;20import java.net.MalformedURLException;21import java.net.URL;22import java.util.Map;23import org.openqa.selenium.remote.DesiredCapabilities;24import org.openqa.selenium.remote.RemoteWebDriver;25import org.testng.annotations.Test;26import com.qaprosoft.carina.core.foundation.webdriver.device.Device;27public class GetCapabilitiesDemo {28 public void testGetCapabilities() throws MalformedURLException {29 DesiredCapabilities capabilities = Device.getCapabilities("chrome");30 Map<String, Object> caps = driver.getCapabilities().asMap();31 for (String key : caps.keySet()) {32 System.out.println("Key: " + key + " Value: " + caps.get(key));33 }34 driver.quit();35 }36}37package com.qaprosoft.carina.demo;38import java.net.MalformedURLException;39import java.net.URL;40import java.util.Map;41import org.openqa.selenium.remote.DesiredCapabilities;42import org.openqa.selenium.remote.RemoteWebDriver;43import org.testng.annotations.Test;44import com.qaprosoft.carina.core.foundation.webdriver.device.Device;45public class GetCapabilitiesDemo {46 public void testGetCapabilities() throws MalformedURLException {47 DesiredCapabilities capabilities = Device.getCapabilities("chrome");

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;3public class 1 {4public static void main(String[] args) {5 Device device = DevicePool.getDevice("Android");6 System.out.println(device.getCapabilities());7 }8}9{appActivity=, appPackage=, appWaitActivity=, appWaitPackage=, appWaitDuration=20000, appiumVersion=1.6.5, automationName=UiAutomator2, autoGrantPermissions=true, autoWebview=true, deviceName=Android, fullReset=false, newCommandTimeout=600, noReset=true, platformName=Android, platformVersion=8.1.0, udid=emulator-5554, unlockKey=, unlockType=, autoAcceptAlerts=true, autoDismissAlerts=true, autoLaunch=true, browserName=Chrome, chromeOptions={args=[], extensions=[]}, databaseEnabled=false, desired={appActivity=, appPackage=, appWaitActivity=, appWaitPackage=, appWaitDuration=20000, appiumVersion=1.6.5, automationName=UiAutomator2, autoGrantPermissions=true, autoWebview=true, deviceName=Android, fullReset=false, newCommandTimeout=600, noReset=true, platformName=Android, platformVersion=8.1.0, udid=emulator-5554, unlockKey=, unlockType=, autoAcceptAlerts=true, autoDismissAlerts=true, autoLaunch=true, browserName=Chrome, chromeOptions={args=[], extensions=[]}, databaseEnabled=false, locationContextEnabled=false, networkConnectionEnabled=false, platform=ANY, takesScreenshot=true, version=, webStorageEnabled=false}, locationContextEnabled=false, networkConnectionEnabled=false, platform=ANY, takesScreenshot=true, version=, webStorageEnabled=false}10import com.qaprosoft.carina.core.foundation.webdriver.device.Device;11import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;12public class 2 {13public static void main(String[] args) {14 Device device = DevicePool.getDevice("Android");15 System.out.println(device.getCapabilities

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.webdriver.device.Device;5public class TestGetCapabilities {6 public void getCapabilities() {7 DesiredCapabilities capabilities = Device.getCapabilities();8 System.out.println(capabilities.getCapability("platformName"));9 System.out.println(capabilities.getCapability("platformVersion"));10 System.out.println(capabilities.getCapability("deviceName"));11 System.out.println(capabilities.getCapability("automationName"));12 System.out.println(capabilities.getCapability("appPackage"));13 System.out.println(capabilities.getCapability("appActivity"));14 System.out.println(capabilities.getCapability("app"));15 System.out.println(capabilities.getCapability("browserName"));16 System.out.println(capabilities.getCapability("platform"));17 System.out.println(capabilities.getCapability("name"));18 System.out.println(capabilities.getCapability("udid"));19 System.out.println(capabilities.getCapability("newCommandTimeout"));20 System.out.println(capabilities.getCapability("fullReset"));21 System.out.println(capabilities.getCapability("noReset"));22 System.out.println(capabilities.getCapability("autoGrantPermissions"));23 System.out.println(capabilities.getCapability("appWaitActivity"));24 System.out.println(capabilities.getCapability("appWaitDuration"));25 System.out.println(capabilities.getCapability("appWaitPackage"));26 System.out.println(capabilities.getCapability("autoAcceptAlerts"));27 System.out.println(capabilities.getCapability("autoDismissAlerts"));28 System.out.println(capabilities.getCapability("autoLaunch"));29 System.out.println(capabilities.getCapability("automationName"));30 System.out.println(capabilities.getCapability("deviceReadyTimeout"));31 System.out.println(capabilities.getCapability("deviceScreenSize"));32 System.out.println(capabilities.getCapability("deviceUDID"));33 System.out.println(capabilities.getCapability("ignoreUnimportantViews"));34 System.out.println(capabilities.getCapability("intentAction"));35 System.out.println(capabilities.getCapability("intentCategory"));36 System.out.println(capabilities.getCapability("intentFlags"));37 System.out.println(capabilities.getCapability("intentPackage"));38 System.out.println(capabilities.getCapability("intentWaitDuration"));39 System.out.println(capabilities.getCapability("keyAlias"));40 System.out.println(capabilities.getCapability("keyPassword"));41 System.out.println(capabilities.getCapability("keystorePassword"));42 System.out.println(capabilities.getCapability("keystorePath"));

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.webdriver.device.Device;4public class Capabilities {5 public void test() {6 Device.getCapabilities();7 }8}9{appPackage=com.android.calculator2, appActivity=.Calculator, appWaitActivity=.Calculator, platformVersion=7.0, platformName=Android, deviceName=Android, appWaitPackage=com.android.calculator2}10Syntax: public static String getDeviceName()11package com.qaprosoft.carina.demo;12import org.testng.annotations.Test;13import com.qaprosoft.carina.core.foundation.webdriver.device.Device;14public class Capabilities {15 public void test() {16 System.out.println(Device.getDeviceName());17 }18}19Syntax: public static String getPlatformVersion()20package com.qaprosoft.carina.demo;21import org.testng.annotations.Test;22import com.qaprosoft.carina.core.foundation.webdriver.device.Device;23public class Capabilities {24 public void test() {25 System.out.println(Device.getPlatformVersion());26 }27}28Syntax: public static String getPlatformName()29package com.qaprosoft.carina.demo;30import org.testng.annotations.Test;31import com.qaprosoft.carina.core.foundation.webdriver.device.Device;32public class Capabilities {33 public void test() {34 System.out.println(Device.getPlatformName());35 }36}37Syntax: public static String getDeviceUDID()

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 Device device = new Device();4 device.getCapabilities();5 }6}7{platformName=Android, deviceName=Android, appPackage=com.android.calculator2, appActivity=com.android.calculator2.Calculator, app=src/test/resources/apps/Calculator.apk, newCommandTimeout=3600, automationName=uiautomator2}8public class 2 {9 public static void main(String[] args) {10 Device device = new Device();11 device.getCapabilities();12 }13}14{platformName=Android, deviceName=Android, appPackage=com.android.calculator2, appActivity=com.android.calculator2.Calculator, app=src/test/resources/apps/Calculator.apk, newCommandTimeout=3600, automationName=uiautomator2}

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1public class GetCapabilitiesDemo {2public static void main(String[] args) throws Exception {3System.out.println("Starting test");4DesiredCapabilities capabilities = Device.getCapabilities("Android");5System.out.println("Capabilities: " + capabilities);6}7}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful