//本文讲解:启动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)

appium(13)- server config的更多相关文章

  1. Apache报错信息之Invalid command 'Order', perhaps misspelled or defined by a module not included in the server config

    今天配置开启Apache虚拟主机时, 然后日志报错提示: Invalid command 'Order', perhaps misspelled or defined by a module not ...

  2. 玩转Spring Cloud之配置中心(config server &config client)

     本文内容导航: 一.搭建配置服务中心(config server) 1.1.git方式 1.2.svn方式 1.3.本地文件方式 1.4.解决配置中包含中文内容返回乱码问题 二.搭建配置消费客户端( ...

  3. appium for iOS config

    appium-doctor: Running iOS Checks ✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer ...

  4. openSuSE DNS SERVER CONFIG

    system:openSuSE 12.3(much better and frendly than the 12.1 in network config)1,network config,attent ...

  5. oracle server config

    安装oracle数据库软件 database/runInstaller; ##执行该程序开始安装 创建数据库 在oracle用户的图形界面oracle用户中 新开启一个终端,直接输入命令dbca会弹出 ...

  6. ubuntu tftp server config

    1.安装tftp-server sudo apt-get install tftpd-hpa sudo apt-get install tftp-hpa(如果不需要客户端可以不安装) tftp-hpa ...

  7. ubuntu nfs server config

    (1)#sudo apt-get install nfs-kernel-server 打开/etc/exports文件,在末尾加入: /home/hyq *(rw,sync,no_root_squas ...

  8. appium server日志分析

    文章出处http://blog.csdn.net/yan1234abcd/article/details/60765295 每次运行测试,可以从Appium Server控制台看到有特别多的日志输出, ...

  9. Appium Server源码分析之作为Bootstrap客户端

    Appium Server拥有两个主要的功能: 它是个http服务器,它专门接收从客户端通过基于http的REST协议发送过来的命令 他是bootstrap客户端:它接收到客户端的命令后,需要想办法把 ...

随机推荐

  1. LeetCode OJ——Text Justification

    http://oj.leetcode.com/problems/text-justification/ 编译代码要看warnings!它提供了可能出问题的情况,比如类型转换上unsigned int ...

  2. 使用Zint和Zxing实现二维码的编码与解码(Using open-source tools to generate and decode Q-R code)

    1.Zint生成二维码 http://sourceforge.net/projects/zint/ [1]从上述站点下载Zint工具 [2]安装Zint工具 [3]使用Zint工具生成二维码,注意选择 ...

  3. AC日记——【模板】最小费用最大流 P3381

    题目描述 如题,给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表 ...

  4. 洛谷——P1187 3D模型

    P1187 3D模型 题目描述 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若干个1×1×1的立方体搭建而成(也就是所有建筑的底部都在同一平面上 ...

  5. Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085 题意: 问你有多少个上升子序列. 思路: dp[i]表示以第i个数结尾的 ...

  6. sqlserverinternals.com

    http://sqlblog.com/blogs/kalen_delaney/default.aspx https://sqlserverinternals.com/

  7. 设计模式之状态模式(State)摘录

    23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程,它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...

  8. 【工作笔记】Git与Github经常使用使用方法

    Git安装 http://www.liaoxuefeng.com/ Git配置用户信息: git config –global user.name "SCOTT" git conf ...

  9. Web文件的ContentType类型大全

    ".*"="application/octet-stream"".001"="application/x-001"&qu ...

  10. JSP技术基础(动态网页基础)

    前言:如果说html为静态网页基础,那么jsp就是动态网页基础,两者的区别就是jsp在html的前面多加了几行而已.当然,jsp里面对java的支持度更高.要明白,js只是嵌入在客户端的小程序小脚本而 ...