appium长时间运行内存溢出解决方式

Python08

appium长时间运行内存溢出解决方式,第1张

下班的时候开始执行,第二天来的时候发现没跑完,appium各种异常,后来看了appium的log发现是内存溢出了,报错如下:

<--- Last few GCs --->

[68480:0x102845000] 22938475 ms: Mark-sweep 4085.6 (4104.9) ->4085.6 (4104.9) MB, 54.7 / 0.0 ms  (average mu = 0.957, current mu = 0.000) last resort GC in old space requested

[68480:0x102845000] 22938532 ms: Mark-sweep 4085.6 (4104.9) ->4085.6 (4104.4) MB, 56.5 / 0.0 ms  (average mu = 0.922, current mu = 0.000) last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x57e8fedbe3d]

Security context: 0x078c1981e6e9 <JSObject>

    1: test [0x78c19809561](this=0x078c4a932069 >,0x078c1f607219 )

    2: truncate [0x78ccb9c31a9] [/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/lodash/lodash.js:~15070] [pc=0x57e90fd3b85](this=0x078c14...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

 1: 0x10003d035 node::Abort() [/usr/local/bin/node]

 2: 0x10003d23f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]

 3: 0x1001b8e15 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]

 4: 0x100586d72 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]

 5: 0x100590274 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]

 6: 0x100561b25 v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]

 7: 0x100693c38 v8::internal::String::SlowFlatten(v8::internal::Handle, v8::internal::PretenureFlag) [/usr/local/bin/node]

 8: 0x100779c08 v8::internal::RegExpImpl::IrregexpExec(v8::internal::Handle, v8::internal::Handle, int, v8::internal::Handle) [/usr/local/bin/node]

 9: 0x10081c670 v8::internal::Runtime_RegExpExec(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]

10: 0x57e8fedbe3d 

Abort trap: 6

于是上网找了以下的几种方式:

1.使用终端运行appium ,并且把appium内存扩展到4096MB

    我的是:node --max_old_space_size=4096 /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js -p 4723     

2.logcat.js文件注释push

附上当时eclipse的报错:

1、

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: read ECONNRESET

Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'

System info: host: 'ruby-Mac.local', ip: 'fe80:0:0:0:69:1eb2:920:7aaf%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2'

Driver info: io.appium.java_client.ios.IOSDriver

2、

org.openqa.selenium.NoSuchSessionException: Session does not exist

Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'

System info: host: 'ruby-Mac.local', ip: 'fe80:0:0:0:69:1eb2:920:7aaf%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2'

Driver info: io.appium.java_client.ios.IOSDriver

appium是一个开源的移动端自动化测试框架,可以测试原生的、混合的以及移动端的web项目,appium是跨平台的,可以运行在osx、windows以及linux桌面系统上,用来测试ios、android应用

Selenium

2004年,Thoughtworks的员工Jason Huggins编写了一个名为JavaScriptTestRunner的测试工具

后来多人修改架构为独立服务模式,开发并推出了Selenium RC和Selenium-IDE

Selenium是一个用于Web应用程序测试的工具,Selenium测试直接运行在浏览器中,就像真正的用户在操作一样

这个工具的主要功能包括:

测试与浏览器的兼容性

测试你的应用程序看是否能够很好的工作在不同浏览器和操作系统之上

测试系统功能

创建回归测试检验软件功能和用户需求

框架底层使用JavaScript模拟真实用户对浏览器进行操作

1.x版本的Selenium需要启动一个Server,将操作Web元素的API调用转化为一段段Javascript,然后在浏览器中注入这段Javascript

但是这样会有缺点

速度慢

依赖于浏览器对注入的Javascript的正确解释

于是有了2.x版本的Selenium版本

2.x版本的Selenium整合了webdriver和原来的Selenium,把多个浏览器原生的API封装成一套更加面向对象的Selenium webdriver API

这样做的好处是速度提高,且调用的稳定性交给了浏览器

2.x的Selenium也可以叫Webdriver

Appium

为什么讲appium前,提到selenium呢?

Appium是基于webdriver协议添加了对移动设备自动化api扩展而成的,这样做的好处是避免重复造轮子

appium的框架是什么样的?

appium使用client-server架构,appium-client以脚本的形式,支持多种语言

appium-server需要安装appium-server程序,用来监听端口上来自appium-client的命令

appium-server已经很久没更新过版本了, 目前可以用appium-desktop代替

UiAutomator是谷歌推出的一款用Java编写的UI测试框架,可以使用UiAutomator框架提供的API来对安卓系统进行一系列的自动化测试操作

Bootstrap是Appium在初始化的时推送到Android手机上的一个UiAutomator测试脚本,该脚本的唯一一个测试方法所做的事情是在手机端开启一个SocketServer(通信模块),用来监听Appium从PC端过来的命令发送给UiAutomator来执行处理

工作原理

appium-server启动并监听在某个端口,接收测试脚本发来的命令请求,再将请求发送给中间件Bootstrap.jar, 中间件Bootstrap.jar会把appium的命令转换成UiAutomator的命令 ,发送给UiAutomator,UiAutomator对android系统进行操作

安装

更多内容,在 汽车网络诊断通信 上可以看到