51Testing软件测试论坛

标题: Appium自动化测试遇到的chromedriver/chrome坑 [打印本页]

作者: lsekfe    时间: 2020-11-3 09:58
标题: Appium自动化测试遇到的chromedriver/chrome坑
一、前言

  app的webview自动化是依赖于chromedriver的,并且每个app的webview版本号都不太一样,这就导致了每次都需要重新去下载对应的chromedriver版本。如何根据当前的webdriver版本去匹配对应chromedriver版本,这是一个难题。
  根据官方文档翻译过来看,版本不匹配的话一般会报错:
  1. An unknown server-side error occurred while processing the command.

  2.   Original error: unknown error: Chrome version must be >= 55.0.2883.0
复制代码
二、Chrome driver启动

  用chrome浏览器运行自动化测试用例时,如果报这样的错误
  1. selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing value
复制代码
可以这样来解决:指定chromedriver.exe驱动绝对路径
  driver = webdriver.Chrome(r'e:\xxx\chromedriver.exe')
  三、常遇错误
  我们在使用native和h5混合的应用程序测试时,可能会遇到报错
  1. E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:1031:

  2.   UserWarning: name used for saved screenshot does not match file type. It should end with a `.png` extension。

  3.   "type. It should end with a `.png` extension", UserWarning)

  4.   ..['NATIVE_APP', 'WEBVIEW_chrome', 'WEBVIEW_com.android.browser']

  5.   NATIVE_APP

  6.   Doctor my center Test Over.

  7.   E

  8.   =====================================================

  9.   ERROR: test_e_AboutContact (__main__.center)

  10.   ----------------------------------------------------------------------

  11.   Traceback (most recent call last):

  12.   File "E:/ATS/TCyDoctorNew/test_case/test_dir/test_4doctormycenter.py", line 371, in test_e_AboutChengyiContact driver.switch_to.context('WEBVIEW_com.android.browser')

  13.   File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context

  14.   self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})

  15.   File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute

  16.   self.error_handler.check_response(response)

  17.   File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response raise wde

  18.   File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response

  19.   super(MobileErrorHandler, self).check_response(response)

  20.   File "E:\Program Files (x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response

  21.   raise exception_class(message, screen, stacktrace)

  22.   selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '55.0.2883'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details.

  23.   ----------------------------------------------------------------------

  24.   Ran 3 tests in 66.001s

  25.   FAILED (errors=1)

  26.   Process finished with exit code 0
复制代码
我们来看报错信息,第一个是warning,是指截图的格式最好是png,这个与本文无关我们先忽略,关键看第二个错误,它主要缘于“No Chromedriver found that can automate Chrome '55.0.2883”,在appium日志里也能看到详情
[attach]130476[/attach]
四、了解chromedriver
  通过管理Chromedriver, Appium支持安卓网页和支持谷歌的混合app的自动化。通过npm package安装的总是绑定最新的chromedriver。








欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2