其他测试框架 AppiumLibrary 和 Selenium2Library 能一块用吗?

irisliu · 2015年06月11日 · 最后由 irisliu 回复于 2015年06月12日 · 1425 次阅读

Robotframework+Selenium2Library+AppiumLibrary

我们要测试一个 android hybird app

我尝试使用 appium open application 打开 app 并能成功 switch to webview
接下来想用 Sleniume2LIbrary keyword 操作页面 但是一直得到错误说 canot active webview。robot case 和结果如下

这 2 个 library 是不是不能一起使用?

也尝试了用 open browser 打开 app 然后想利用 appium 的 swtich context 但是报错 no application open。如何能同时使用 2 个 library 呢。。

${desired_capabilities} Create Dictionary        browserName=Android    platformName=Android    deviceName=f0ba3776    
Open Application    http://localhost:4723/wd/hub
sleep   30
get contexts    
log 3
sleep   2
${print}    Get Current Context
switch to context   WEBVIEW_com.sg.sg.bmw
${print}    Get Current Context
log 4
sleep   20
Wait Until Page Contains Element    ${BMW USERNAME XPATH}

=================
结果如下:

20150611 11:47:32.970 : INFO : ${desired_capabilities} = {u'browserName': u'Android', u'platformName': u'Android', u'deviceName': u'f....
20150611 11:48:14.485 : INFO : Slept 30 seconds
20150611 11:48:16.984 : INFO : [u'NATIVE_APP', u'WEBVIEW_com.tencent.news', u'WEBVIEW_com.android.browser', u'WEBVIEW_com.android.settings', u'WEBVIEW_com.sg.sg.bmw']
20150611 11:48:16.987 : INFO : 3
20150611 11:48:18.991 : INFO : Slept 2 seconds
20150611 11:48:18.998 : INFO : ${print} = NATIVE_APP
20150611 11:48:21.002 : INFO : ${print} = WEBVIEW_com.sg.sg.bmw
20150611 11:48:21.004 : INFO : 4
20150611 11:48:41.023 : INFO : Slept 20 seconds
20150611 11:48:41.520 : FAIL :
WebDriverException: Message: unknown error: cannot activate web view
(Session info: webview=)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.10.0 x86_64)

20150611 11:48:41.522 : WARN :
Keyword 'Capture Page Screenshot' could not be run on failure: WebDriverException: Message: unknown error: cannot activate web view
(Session info: webview=)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.10.0 x86_64)

20150611 11:48:41.523 : FAIL :
WebDriverException: Message: unknown error: cannot activate web view
(Session info: webview=)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.10.0 x86_64)

20150611 11:48:41.525 : WARN :
Keyword 'Capture Page Screenshot' could not be run on failure: WebDriverException: Message: unknown error: cannot activate web view
(Session info: webview=)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.10.0 x86_64)

20150611 11:48:41.546 : FAIL : No browser is open
Starting test: RobotCase PK Mantenance.Robot - PK.TestSuit.Login.Login.005_Login with Correct UserName and Correct Password
Ending test: RobotCase PK Mantenance.Robot - PK.TestSuit.Login.Login.005_Login with Correct UserName and Correct Password

共收到 6 条回复 时间 点赞

添加头像,请使用 md 来写帖子。否则删除

@chenhengjie123 @jennifer 请帮忙看看有没有遇到过这个问题。多谢多谢。

在相同的关键字前加上各自的库名和.就可以了
不过。。失败自动截图的时候 会报错。因为两个库的截图方法会冲突

#2 楼 @irisliu 两个 Library 的实例是分别独立的。它们各自有一个缓存池存储自身的 driver 实例。所有方法调用都是调用 driver 实例的方法。
我想你想做的是在 appiumLibrary 里面加入 Selenium2Library 的方法吧(毕竟 Selenium2Library 封装的方法数量更多,用起来也更方便)。这个只能你自己结合这两个 library 创造一个自己的 Library 了。

实现的思路主要是把 Selenium2Library 的所有方法里面获取 driver 实例的方法改为获取 AppiumLibrary 的,然后就可以用了。名字重复的一定要看清楚到底实现是否一致。

#3 楼 @wang0417库名.不行,appium 的能过去 ,selenium2 的 keyword 还是报错

#4 楼 @chenhengjie123 是这个目的,selenium2 的 keyword 多,想利用。我先去学习下 driver 实例的问题。多谢。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册