python/Appium遇到问题

报错:

 Original error: Could not proxy command to remote server. Original error: Error: socket hang up

 

使用参数化来跑test case

 @parameterized.expand([
('manshuo.li@tss.com', '123456',''),
('manshuo.li@tsl.com', '123455','Password Incorrect'),
('manshuo.i@tssl.com', '123456','Account does not exist')
])
# @Common.getImage
def test_login(self,username,password,message):
logging.info('==========test_login========')
user = login(self.driver)

self.assertTrue(user.login_action(self.driver,username,password))
if message == '':

self.assertTrue(user.check_login_status(username))
else:
self.assertTrue(user.check_toast(message))
sleep(3)



-----------------------------


遇到问题:

当使用三个用例参数组合去跑
中间那个会识别不到toast,看到现象就是感觉进程很快被杀掉进行下个用例参数
然后报

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up

 

若单独允许该用例,则成功

目前正在查找原因。

 

 

 

调用函数报错:

self.input_text(*self.enterName,username)
TypeError: input_text() missing 1 required keyword-only argument: 'text'

 

被调函数:

def input_text(self,*loc,text):
    '''
封装输入操作函数
'''
self.input = self.find_element(*loc)
self.input.clear()
self.input.send_keys(text)


调用函数:
self.input_text(*self.enterName,username)

参数个数是对的,但是会报找不到的错误。

解决:
百度了一下,其实是个很低级的错误,学python时学习过但无在实践中遇到。
需复习一下可变参数的概念


python自定义函数中有两种不定长参数,第一种是*name,第二种是**name。
加了星号 * 的参数会以元组(tuple)的形式导入,存放所有未命名的变量参数。
加了两个星号 ** 的参数会以字典的形式导入
第一种形式的不定长参数,在传入额外的参数时可以不用指明参数名,直接传入参数值即可,第二种因为返回的是字典,所以传入时需要指定参数名。
例子:
1 def funA(a, b, *args):
2     print(a)
3     print(b)
4     print(args)
5 
6 
7 funA(1, 2, 3, 5, 6, 7)


输出如下:
1
2
(3, 5, 6, 7)

args为后面所有的参数,以元组方式呈现:(3, 5, 6, 7)
https://blog.csdn.net/hanhanwanghaha/article/details/105920371

所以就回答了本来的那个报错,因为
input_text(self,*loc,text)第一个参数为不定长参数,所以它把后面的参数全部传给*loc,text就读不到值

解决方式很简单:
将不定长参数放最后

input_text(self,text,*loc)



启动appium报错uncaughtException: primordials is not defined 
本来想写个bat启动appium,结果报错如上。
参考:
https://www.cnblogs.com/bugbreak/p/12518519.html

通过cmd命令的方式启动appium,一定要注意appium版本和node.js版本的匹配问题 
否则在cmd中执行appium命令会报错

1.先尝试更新appium版本,使用命令查看appium版本为1.4,node版本为v13.1.0
在官网下载appium 1.18看看行不行。安装后这个是appium desktop。所以不行,只能降级nodejs到v10以下

 

 

 
posted @ 2020-10-10 21:27  lms21  阅读(425)  评论(0)    收藏  举报