Skip to content

Commit

Permalink
In latest version of appium, browserName capability needs to be set e…
Browse files Browse the repository at this point in the history
…xplicitly.

Using the existing capability browserName to be used while creating mobile sessions.
  • Loading branch information
Kumar Vikram authored and Doug Simmons committed Sep 28, 2017
1 parent f3fc075 commit 2ef49fe
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public class AppiumCapabilitiesBuilder extends DefaultCapabilitiesBuilder {
public DesiredCapabilities getCapabilities(DesiredCapabilities capabilities) {

MobileTestSession mobileSession = Grid.getMobileTestSession();

capabilities.setCapability(MobileCapabilityType.APP, mobileSession.getAppName());

if(StringUtils.isNotBlank(mobileSession.getAppName())){
capabilities.setCapability(MobileCapabilityType.APP, mobileSession.getAppName());
}

if (StringUtils.isBlank(mobileSession.getAppName())) {
capabilities.setCapability(MobileCapabilityType.APP, mobileSession.getAppPath());
}
Expand All @@ -58,6 +61,8 @@ public DesiredCapabilities getCapabilities(DesiredCapabilities capabilities) {
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, mobileSession.getPlatformVersion());
capabilities.setCapability(MobileCapabilityType.LOCALE, mobileSession.getAppLocale());
capabilities.setCapability(MobileCapabilityType.LANGUAGE, mobileSession.getAppLanguage());
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, mobileSession.getBrowserName());

if (mobileSession.getPlatform() == WebDriverPlatform.ANDROID) {
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, APPIUM_ANDROID_PLATFORM_TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class AppiumAndroidBrowserSauceCloudTest {

@Test
@MobileTest(appName = "browser", device = "android:4.4", deviceType = "Android Emulator", additionalCapabilities = {
@MobileTest(browserName = "browser", device = "android:4.4", deviceType = "Android Emulator", additionalCapabilities = {
"appiumVersion:1.4.13" })
public void testWithChrome() {
RemoteWebDriver driver = Grid.driver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AppiumAndroidBrowserTest {
* versions.
*/
@Test
@MobileTest(appName = "Chrome", device = "android:5.1", deviceType = "Android Emulator")
@MobileTest(browserName = "Browser", device = "android:5.1", deviceType = "Android Emulator")
public void testWithChrome() {
RemoteWebDriver driver = Grid.driver();
assertNotNull(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class AppiumIOSSafariSauceCloudTest {

@Test
@MobileTest(appName = "safari", device = "iphone:8.1", deviceType = "iPhone Simulator", additionalCapabilities = {
@MobileTest(browserName = "safari", device = "iphone:10.2", deviceType = "iPhone SE", additionalCapabilities = {
"appiumVersion:1.4.13" })
public void testWithSafari() {
RemoteWebDriver driver = Grid.driver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testWithNativeAppAllInternationalMountains() throws InterruptedExcep
}

@Test
@MobileTest(appName = "safari", device = "iphone:8.1", deviceType = "iPhone Simulator")
@MobileTest(browserName = "safari", device = "iphone:8.1", deviceType = "iPhone Simulator")
public void testWithSafari() {
RemoteWebDriver driver = Grid.driver();
assertNotNull(driver);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-2016 PayPal |
| Copyright (C) 2014-2017 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand Down Expand Up @@ -124,5 +124,11 @@
* This parameter specifies to execute mobile test cases using respective mobile driver.
*/
String mobileNodeType() default "";

/**
* This parameter specifies the name of the browser
*
*/

String browserName() default "";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-2016 PayPal |
| Copyright (C) 2014-2017 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand Down Expand Up @@ -52,6 +52,7 @@ public class MobileTestSession extends AbstractTestSession {
private String appVersion;
private String androidAppMainActivity;
private String androidAppPackage;
private String browserName;

private WebDriverPlatform platform;

Expand Down Expand Up @@ -122,7 +123,11 @@ public String getDeviceType() {
return deviceType;
}

@Override
public String getBrowserName() {
return browserName;
}

@Override
public void startSession() {
logger.entering();
Grid.getThreadLocalWebDriver().set(MobileDriverFactory.createInstance());
Expand Down Expand Up @@ -176,6 +181,10 @@ public void initializeTestSession(InvokedMethodInformation method) {
if (StringUtils.isNotBlank(getLocalConfigProperty(ConfigProperty.ANDROID_APP_PACKAGE))) {
androidAppPackage = getLocalConfigProperty(ConfigProperty.ANDROID_APP_PACKAGE);
}

if (StringUtils.isNotBlank(getLocalConfigProperty(ConfigProperty.BROWSER))) {
browserName = getLocalConfigProperty(ConfigProperty.BROWSER);
}

// Override values when supplied via the annotation
if (deviceTestAnnotation != null) {
Expand Down Expand Up @@ -204,6 +213,9 @@ public void initializeTestSession(InvokedMethodInformation method) {
if (StringUtils.isNotBlank(deviceTestAnnotation.mobileNodeType())) {
mobileNode = deviceTestAnnotation.mobileNodeType();
}
if (StringUtils.isNotBlank(deviceTestAnnotation.browserName())) {
this.browserName = deviceTestAnnotation.browserName();
}
this.mobileNodeType = MobileNodeType.getMobileNodeType(mobileNode);

initializeAdditionalCapabilities(method);
Expand All @@ -212,14 +224,20 @@ public void initializeTestSession(InvokedMethodInformation method) {
}

boolean appPathProvided = StringUtils.isNotBlank(appPath);

//App run and browser run should be mutually exclusive. If appName or appPath is provided disregard
//the browser parameter
if(StringUtils.isNotBlank(appName) || StringUtils.isNotBlank(appPath)){
this.browserName = ""; //to nullify the default value *firefox
}

checkArgument(!(mobileNodeType != MobileNodeType.APPIUM && appPathProvided),
"appPath can be specified for appium only, Please specify appName instead of appPath");

checkArgument(
StringUtils.isNotBlank(appName) ^ StringUtils.isNotBlank(appPath),
"Either you have provided both appPath and appName or you have specified nothing. Please specify either "
+ "appPath or appName");
StringUtils.isNotBlank(appName) ^ StringUtils.isNotBlank(appPath) ^ StringUtils.isNotBlank(browserName),
"Either you have provided appPath, appName, and browserName all at once or you have specified nothing. "
+ "Please specify one of appPath, appName, or browserName");

checkArgument(isDeviceDefined(),
"The device should either be provided as 'device name:version' or 'device' or 'device:version'." +
Expand All @@ -233,10 +251,10 @@ public void initializeTestSession(InvokedMethodInformation method) {
}

// appPath can be passed via the annotation or as a config var. It may need formatting.
if (this.appPath.startsWith(SELION_HUB_STORAGE)) {
if (appPathProvided && this.appPath.startsWith(SELION_HUB_STORAGE)) {
// parse and construct the absolute url for selion hub storage
this.appPath = getSelionHubStorageUrl(this.appPath);
} else if (!this.appPath.startsWith(SAUCE_URL) && !StringUtils.startsWithIgnoreCase(appPath, "http")) {
} else if (appPathProvided && !this.appPath.startsWith(SAUCE_URL) && !StringUtils.startsWithIgnoreCase(appPath, "http")) {
// construct the absolute url for apps exist in resource folder.
Path p = Paths.get(appPath);
if (!p.isAbsolute()) {
Expand Down

0 comments on commit 2ef49fe

Please sign in to comment.