//本文讲解:启动server时,如何配置capabilities 和 flag。可以将不同client端需要的通用的capabilities都放到server端配置。

Requirements

  • Installed Node.js 0.12 or greater.

  • At least an appium server instance installed via npm.

The basic principle.

It works the similar way as common ChromeDriverInternetExplorerDriver of Selenium project or PhantomJSDriver. They use subclasses of the DriverService.

Which capabilities this feature provides

This feature providese abilities and options of the starting of a local Appium node server. End users still able to open apps as usual

    DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
driver = new AndroidDriver<>(new URL("remoteOrLocalAddress"), capabilities);

when the server is launched locally\remotely. Also user is free to launch a local Appium node server and open their app for the further testing the following way:

    DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
driver = new AndroidDriver<>(capabilities);

How to prepare the local service before the starting

If there is no specific parameters then

    import io.appium.java_client.service.local.AppiumDriverLocalService;
... AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
service.start();
...
service.stop();

FYI

There are possible problems related to local environment which could break this:

AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();

It is more usual for UNIX/LINUX-like OS's. Also there are situations when should be used an another Node.JS instance, e.g. the instance which is installed in the directory that differs from one defined at the PATH environmental variable. The same may be true for Appium node server (it is related to appium.js file (v <= 1.4.16) and main.js (v >= 1.5.0)).

At this case user is able to set up values of the NODE_BINARY_PATH (The environmental variable used to define the path to executable NodeJS file (node.exe for WIN and node for Linux/MacOS X)) and the APPIUM_BINARY_PATH (The environmental variable used to define the path to executable appium.js (1.4.x and lower) or main.js (1.5.x and higher)) environmental variables/system properties. Also it is possible to define these values programmatically:

//appium.node.js.exec.path
System.setProperty(AppiumServiceBuilder.NODE_PATH ,
"the path to the desired node.js executable"); System.setProperty(AppiumServiceBuilder.APPIUM_PATH ,
"the path to the desired appium.js or main.js"); AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();

If there should be non default parameters specified then

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
... AppiumDriverLocalService service = AppiumDriverLocalService.
buildService(new AppiumServiceBuilder().
withArgument(GeneralServerFlag.TEMP_DIRECTORY,
"The_path_to_the_temporary_directory"));

or

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
... AppiumDriverLocalService service = new AppiumServiceBuilder().
withArgument(GeneralServerFlag.TEMP_DIRECTORY,
"The_path_to_the_temporary_directory").build();

Lists of available server side flags are here:

  • io.appium.java_client.service.local.flags.GeneralServerFlag;
  • io.appium.java_client.service.local.flags.AndroidServerFlag;
  • io.appium.java_client.service.local.flags.IOSServerFlag

Which parameters also can be defined

  • If it is necessary to define some specific port or any free port
new AppiumServiceBuilder().usingPort(4000);

or

new AppiumServiceBuilder().usingAnyFreePort();
  • If it is necessary to use another IP address
new AppiumServiceBuilder().withIPAddress("127.0.0.1");
  • If it is necessary to define output log file
import java.io.File;
... new AppiumServiceBuilder().withLogFile(logFile);
  • If it is necessary to define another Node.js executable file
import java.io.File;

...

new AppiumServiceBuilder().usingDriverExecutable(nodeJSExecutable);
  • If it is necessary to define another appium.js/main.js file
import java.io.File;

...
//appiumJS is the full or relative path to
//the appium.js (v<=1.4.16) or maim.js (v>=1.5.0)
new AppiumServiceBuilder().withAppiumJS(new File(appiumJS));
  • It is possible to define server capabilities (node server v >= 1.5.0)
DesiredCapabilities serverCapabilities = new DesiredCapabilities();
...//the capability filling AppiumServiceBuilder builder = new AppiumServiceBuilder().
withCapabilities(serverCapabilities);
AppiumDriverLocalService service = builder.build();
service.start();
...
service.stop();

Capabilities which are used by a builder can be completed/orerriden any similar way://server端与client端配合,配置capability的例子

DesiredCapabilities serverCapabilities = new DesiredCapabilities();
serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
serverCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true);
serverCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
serverCapabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,
chrome.getAbsolutePath()); //this capability set can be used for all cases AppiumServiceBuilder builder = new AppiumServiceBuilder().
withCapabilities(serverCapabilities);
AppiumDriverLocalService service = builder.build(); DesiredCapabilities clientCapabilities = new DesiredCapabilities();
clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,
"io.appium.android.apis");
clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
".view.WebView1");

then

AndroidDriver<MobileElement> driver =
new AndroidDriver<>(service, clientCapabilities);

or

AndroidDriver<MobileElement> driver =
new AndroidDriver<>(builder, clientCapabilities);

or

service.start();
AndroidDriver<MobileElement> driver =
new AndroidDriver<>(service.getUrl(), clientCapabilities);

How to create an AppiumDriver instance

Many constructors of AndroidDriver/IOSDriver use AppiumDriverLocalService or AppiumServiceBuilder as parameters. The list of constructors is below.

public AndroidDriver(URL remoteAddress,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(URL remoteAddress,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(AppiumDriverLocalService service,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(AppiumDriverLocalService service,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(AppiumServiceBuilder builder,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(AppiumServiceBuilder builder,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public AndroidDriver(org.openqa.selenium.Capabilities desiredCapabilities)
public IOSDriver(URL remoteAddress,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(URL remoteAddress,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(AppiumDriverLocalService service,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(AppiumDriverLocalService service,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(AppiumServiceBuilder builder,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(AppiumServiceBuilder builder,
org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory,
org.openqa.selenium.Capabilities desiredCapabilities) public IOSDriver(org.openqa.selenium.Capabilities desiredCapabilities)

An instance of AppiumDriverLocalService which has passed through constructors will be stopped when

  driver.quit();

If it is necessary to keep the service alive during a long time then something like that is available

  service.start();

  ....

  new IOSDriver<MobileElement>(service.getUrl(), capabilities)

最新文章

  1. windows环境下sublime的nodejs插件详细安装图解
  2. ORA-14450: attempt to access a transactional temp table already in use
  3. Java 分页通用
  4. oracle方案是什么?
  5. WITH RECURSIVE and MySQL
  6. (转) 一步一步学习ASP.NET 5 (五)- TypeScript
  7. Spotlight实时监控Windows Server 2008
  8. SpringMVC自动扫描@Controller注解的bean
  9. AFNetworking框架使用
  10. ansible检测链路状态和切换状态
  11. SQLServer排序时与读取的记录会影响到结果?
  12. 朴素贝叶斯(naive bayes)算法及实现
  13. MEF依赖注入调试小技巧!
  14. jvm 指令集代码
  15. TestNG深入理解
  16. lelnet爱一直在
  17. 简述JavaScript全局对象
  18. eclipse错误GC overhead limit exceeded
  19. IBM WebSphere MQ介绍安装以及配置服务详解
  20. solr 请求参数过长报错,Solr配置maxBooleanClauses属性不生效原因分析

热门文章

  1. Image与Base64String的互转换
  2. jQuery时间验证和转换为标准格式的时间
  3. 《从零开始搭建游戏服务器》项目管理工具Maven
  4. Tavas and Malekas
  5. Linux 在VMware中搭建CentOS6.5虚拟机
  6. iOS -- SKViedoNode类
  7. 【IE】IE对line-height 失效的的解决方案
  8. React学习之常用概念
  9. 自己定义struts2中action类型转换器
  10. GG链路过多port不足导致的报错OGG-01223