//本文讲解:启动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. AC日记——最小路径覆盖问题 洛谷 P2764

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...

  2. latex beamer 插入代码

    有网友在beamer中使用mcode也就是 listings 输出源代码时遇到如下错误: Runaway argument?! Paragraph ended before \lst@next was ...

  3. Codeforces 877E Danil and a Part-time Job(dfs序 + 线段树)

    题目链接   Danil and a Part-time Job 题意    给出一系列询问或者修改操作 $pow$ $x$表示把以$x$为根的子树的所有结点的状态取反($0$变$1$,$1$变$0$ ...

  4. 洛谷——P1238 走迷宫

    P1238 走迷宫 题目描述 有一个m*n格的迷宫(表示有m行.n列),其中有可走的也有不可走的,如果用1表示可以走,0表示不可以走,文件读入这m*n个数据和起始点.结束点(起始点和结束点都是用两个数 ...

  5. 洛谷——P1294 高手去散步

    P1294 高手去散步 题目背景 高手最近谈恋爱了.不过是单相思.“即使是单相思,也是完整的爱情”,高手从未放弃对它的追求.今天,这个阳光明媚的早晨,太阳从西边缓缓升起.于是它找到高手,希望在晨读开始 ...

  6. Codeforces 245G Suggested Friends 暴力乱搞

    G. Suggested Friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Extjs grid 单元格事件

    celldblclick: function (view, td, cellIndex, record, tr, rowIndex, e, eOpts) { //extjs 4.2下,有时出现,多次不 ...

  8. Linux下批量替换文件内容和文件名(转)

    1.批量替换指定多个文件的文件内容 在指定目录/your/path里,查找包含old_string字符串的所有文件,并用new_string字符串替换old_string字符串. sed -i &qu ...

  9. Markdown的css样式源码

    http://www.cnblogs.com/zhangjk1993/p/5442676.html https://github.com/zhangjikai/markdown-css https:/ ...

  10. Hibernate操作Blob数据

      首先看数据库.数据库中新建一个BlobTable表,表中有两个字段,一个id(主键)一个picture字段是Blob类型字段.然后使用Hibernate向该数据库中写入和读取数据 在POJO类中p ...