appium(13)- server config_weixin_30740581的博客-程序员宝宝

技术标签: ViewUI  python  测试  javascript  

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

转载于:https://www.cnblogs.com/superbaby11/p/6102395.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30740581/article/details/97214016

智能推荐

电脑卡,反应速度变慢了,应该这样子弄._attack_5的博客-程序员宝宝

电脑反应慢老是卡怎么办?这是由于长时间使用电脑产生的垃圾文件和缓存造成的。我们要经常对电脑进行定期清理。1.双击“我的电脑”2.c盘右键点属性3.点击磁盘清理4.选择要清理的文件5.删除不要的文件,其他盘也是这样子的操作。6.还可以整理磁盘碎片同样c盘右键属性,找到工具栏7.点击优化可以对各种盘进行优化,这样子电脑反应速度就快了。...

基因数据处理98之SparkBWA运行时spark on Yarn问题日志完整记录_KeepLearningBigData的博客-程序员宝宝

脚本:[email protected]:~/xubo/tools/SparkBWA/build$ cat paired.sh spark-submit --class SparkBWA \ --master yarn-client \ --conf "spark.executor.extraJavaOptions=-XX:MaxPermSize=1024M" --driver-

Failed to add the foreign key constraint. Missing index for constraint ‘stu_ibfk_1‘ in the reference_luckyGirlIT的博客-程序员宝宝

解决方案:作为外键,user表中的id必须是唯一值,因此得添加约束unique,或者primary key;

软件项目管理总体流程设计与分析_行者歌途的博客-程序员宝宝_在按照基本计划、外部设计、内部设计、程序设计、程序开发、测试和操作/维护的顺

软件项目管理总体流程设计与分析1 引言长期以来,软件项目高失败率的状况一直困扰着人们,研究表明,软件项目失败的原因主要有两个:一是应用项目的复杂性;二是缺乏合格的软件项目管理人才。实践证明缺乏有效的项目管理是导致软件项目失控的直接原因。软件开发的风险之所以大,是由于软件过程能力低,其中最关键的问题在于软件开发组织不能很好

即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型,仍已加载来_YUANHUICN的博客-程序员宝宝_即使其mime类型不是有效的

这个错误发生的原因不一,我遇到的是比较简单的一个错误即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型,仍已加载XXX的文件报这个错时在网页查看一下源代码F12查看仔细查看自己的引入jquery路径是否正确,我是少加了一个/希望你能有所收获!...

基于libVLC的视频播放器_小新识图的博客-程序员宝宝_libvlc.dll分割视频

本文来自于:http://blog.csdn.net/leixiaohua1020/article/details/42363079  最简单的基于libVLC的例子:最简单的基于libVLC的视频播放器本文记录使用libVLC的开发的最简单的视频播放器示例。VLC Media Player是一款优秀的播放器,但是由于它的源代码编译的难度比较大,一直没有深入研究过它的开发方面的技术

随便推点

Netpref Test的使用_小黑没脑袋的博客-程序员宝宝

Netperf是一种网络性能测量工具,主要针对基于TCP或UDP的传输,Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求/应答(request/reponse)模式。Netperf测试结果所反映的是一个系统能够以多快的速度向另外一个系统发送数据,以及另外一个系统能够以多块的速度接收数据。一 netperf 简介

向量范数及矩阵范数的简介和matlab实现_simple life的博客-程序员宝宝_矩阵无穷范数matlab

向量范数及矩阵范数的简介和matlab实现欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入...

Hadoop工具安装--Hive_Miss Chim的博客-程序员宝宝

1.下载安装包http://apache.fayea.com/apache-mirror/hive/stable/apache-hive-1.1.0-bin.tar.gz 2.安装(1)上传包--上传hive包到/home/hadoop上(2)解压   tar–zxvf apache-hive-1.1.0-bin.tar.gz(或者直接在ubuntu图形界面上解压安装包)(

2010年全国职称计算机考试专用教程——AutoCAD 2004制图软件 (含光盘下载)_weixin_30739595的博客-程序员宝宝

2010年全国职称计算机考试专用教程——AutoCAD 2004制图软件 (含光盘下载)转载于:https://www.cnblogs.com/gavinhughhu/archive/2010/09/09/1821922.html

ElasticSearch安装与操作_MrGrant的博客-程序员宝宝_elasticsearch 国内镜像下载

一、简介 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎。无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。但是,Lucene只是一个库。想要使用它,你必须使用Java来作为开发语言并将其直接集成到你的应用中,更糟糕的是,Lucene非常复杂,你需要深入了解检索的相关知识来理解它是如何工作的。 Elast...

Unity笔记-29-ARPG游戏项目-06-弓箭_unity射箭_韩天衣的博客-程序员宝宝

Unity笔记-29-ARPG游戏项目-06-弓箭基本要求说明点按R键,进入弓箭视角,点按鼠标左键进行射击,射击距离,伤害以及削韧效果根据蓄力时间而定,每次拉弓到射击的持续时间会不断蓄力,射击距离伤害,削韧效果具有上限,一直蓄力不会无限制的增加距离,伤害,削韧效果;弓箭视角下的移动不会改变人物朝向,人物朝向一直朝向前方,通过再次点按R,跳跃,翻滚等操作可以退出弓箭视角,受到攻击造成硬直时也会退出弓箭视角进入弓箭视角时,屏幕中央会出现射击符号,退出则消失,同时人物的动作朝向应当指向射击符号的位置处于