UiAutomator2 測試 H5 頁面,切換 webview 後報沒有找到對應的 ChromeDriver 版本

Forkey發表於2020-12-24
測試手機:
華為/vivo手機,webView版本是78.0的(其他手機不會出現下面的問題,如:小米、Honor
前置描述
  1. APP已經開啟Debug模式(用appium操作是沒問題的)
  2. 用Chome瀏覽器檢視'chrome://inspect/#devices', 版本如下
現象
  1. chromedriver例項化後,發現會拉起本地Chrome瀏覽器
  2. 接著就報ChromeDriver版本不對

####相關日誌如下:

2020-12-24 15:57:40,404 conftest:INFO:mothod:usb
[W 201224 15:57:40 __init__:203] atx-agent has something wrong, auto recovering
[D 201224 15:57:40 __init__:286] device UJKDU20611008827 is online
[I 201224 15:57:40 init:155] uiautomator2 version: 2.11.0
2020-12-24 15:57:41,438 conftest:INFO:連線裝置:UJKDU20611008827
2020-12-24 15:57:44,776 conftest:INFO:啟動APP成功...
2020-12-24 15:57:47,942 conftest:INFO:切換chromedriver前,先清除chromedriver程式!!
2020-12-24 15:57:49,943 conftest:INFO:start chromedriver instance
2020-12-24 15:57:49,944 conftest:INFO:chrome_driver_path: /Users/leedarson/Documents/codes/python_workplace/Arnoo_ATX2/chromedriver/Darwin/78/chromedriver
Starting ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904@{#877}) on port 9527
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
FAILED

=================================== FAILURES ===================================
___________ TestDistributionNetwork.test_distribution_network_by_ap ____________

self = <cases.distribution_network.test_distribution_network.TestDistributionNetwork object at 0x104c276d0>
common_driver = <uiautomator2.Device object at 0x104c91e80>
env = <tools.mod_config.ReadConfig object at 0x104cb42e0>
log = <tools.Logger.Log object at 0x104cb41c0>, udid = 'UJKDU20611008827'
device_info = {'device_wifi': '9042', 'phone_model': 'norve7', 'phone_name': 'huawei', 'search_keyword': 'Wi-Fi F', ...}

@allure.story('AP配網測試')
def test_distribution_network_by_ap(self, common_driver, env, log, udid, device_info):
allure.dynamic.title("機型[{}]-裝置[{}]".format(device_info['phone_name'], device_info['device_wifi']))

countdown = 130 # 倒數計時時間
app_package = env.get_device("app_package")
app_activity = env.get_device("app_activity")

search_keyword = device_info['search_keyword']
device_wifi = device_info['device_wifi']
phone_name = device_info['phone_name']

enable_wifi = env.get_wifi_device_info('enable_wifi')
wifi_password = env.get_wifi_device_info('wifi_password')
ssid_list_wifi = env.get_wifi_device_info('ssid_list_wifi')
statistical_duration = env.get_wifi_device_info("statistical_duration") # 配網時長

u2 = common_driver
common = CommonMethod(u2, log, udid, app_package)
> driver = ChromeDriver(u2, log, common, phone_name).driver()

cases/distribution_network/test_distribution_network.py:43:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tools/chrome_driver.py:70: in driver
dr = webdriver.Remote('http://localhost:%d' % self._port, capabilities)
/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:157: in __init__
self.start_session(capabilities, browser_profile)
/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:252: in start_session
response = self.execute(Command.NEW_SESSION, parameters)
/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:321: in execute
self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x104cd9430>
response = {'status': 500, 'value': '{"value":{"error":"session not created","message":"session not created: This version of Chro...fff6ef68109 _pthread_start + 148\\n18 libsystem_pthread.dylib 0x00007fff6ef63b8b thread_start + 15\\n"}}'}

def check_response(self, response):
"""
Checks that a JSON response from the WebDriver does not have an error.

:Args:
- response - The JSON response from the WebDriver server as a dictionary
object.

:Raises: If the response contains an error message.
"""

status = response.get('status', None)
if status is None or status == ErrorCode.SUCCESS:
return
value = None
message = response.get("message", "")
screen = response.get("screen", "")
stacktrace = None
if isinstance(status, int):
value_json = response.get('value', None)
if value_json and isinstance(value_json, basestring):
import json
try:
value = json.loads(value_json)
if len(value.keys()) == 1:
value = value['value']
status = value.get('error', None)
if status is None:
status = value["status"]
message = value["value"]
if not isinstance(message, basestring):
value = message
message = message.get('message')
else:
message = value.get('message', None)
except ValueError:
pass

exception_class = ErrorInResponseException
if status in ErrorCode.NO_SUCH_ELEMENT:
exception_class = NoSuchElementException
elif status in ErrorCode.NO_SUCH_FRAME:
exception_class = NoSuchFrameException
elif status in ErrorCode.NO_SUCH_WINDOW:
exception_class = NoSuchWindowException
elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
exception_class = StaleElementReferenceException
elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
exception_class = ElementNotVisibleException
elif status in ErrorCode.INVALID_ELEMENT_STATE:
exception_class = InvalidElementStateException
elif status in ErrorCode.INVALID_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR \
or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
exception_class = InvalidSelectorException
elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
exception_class = ElementNotSelectableException
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
exception_class = ElementNotInteractableException
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
exception_class = InvalidCookieDomainException
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
exception_class = UnableToSetCookieException
elif status in ErrorCode.TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.SCRIPT_TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.UNKNOWN_ERROR:
exception_class = WebDriverException
elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
exception_class = UnexpectedAlertPresentException
elif status in ErrorCode.NO_ALERT_OPEN:
exception_class = NoAlertPresentException
elif status in ErrorCode.IME_NOT_AVAILABLE:
exception_class = ImeNotAvailableException
elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
exception_class = ImeActivationFailedException
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
exception_class = MoveTargetOutOfBoundsException
elif status in ErrorCode.JAVASCRIPT_ERROR:
exception_class = JavascriptException
elif status in ErrorCode.SESSION_NOT_CREATED:
exception_class = SessionNotCreatedException
elif status in ErrorCode.INVALID_ARGUMENT:
exception_class = InvalidArgumentException
elif status in ErrorCode.NO_SUCH_COOKIE:
exception_class = NoSuchCookieException
elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
exception_class = ScreenshotException
elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
exception_class = ElementClickInterceptedException
elif status in ErrorCode.INSECURE_CERTIFICATE:
exception_class = InsecureCertificateException
elif status in ErrorCode.INVALID_COORDINATES:
exception_class = InvalidCoordinatesException
elif status in ErrorCode.INVALID_SESSION_ID:
exception_class = InvalidSessionIdException
elif status in ErrorCode.UNKNOWN_METHOD:
exception_class = UnknownMethodException
else:
exception_class = WebDriverException
if value == '' or value is None:
value = response['value']
if isinstance(value, basestring):
if exception_class == ErrorInResponseException:
raise exception_class(response, value)
raise exception_class(value)
if message == "" and 'message' in value:
message = value['message']

screen = None
if 'screen' in value:
screen = value['screen']

stacktrace = None
if 'stackTrace' in value and value['stackTrace']:
stacktrace = []
try:
for frame in value['stackTrace']:
line = self._value_or_default(frame, 'lineNumber', '')
file = self._value_or_default(frame, 'fileName', '<anonymous>')
if line:
file = "%s:%s" % (file, line)
meth = self._value_or_default(frame, 'methodName', '<anonymous>')
if 'className' in frame:
meth = "%s.%s" % (frame['className'], meth)
msg = " at %s (%s)"
msg = msg % (meth, file)
stacktrace.append(msg)
except TypeError:
pass
if exception_class == ErrorInResponseException:
raise exception_class(response, message)
elif exception_class == UnexpectedAlertPresentException:
alert_text = None
if 'data' in value:
alert_text = value['data'].get('text')
elif 'alert' in value:
alert_text = value['alert'].get('text')
raise exception_class(message, screen, stacktrace, alert_text)
> raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 78

/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py:242: SessionNotCreatedException
------------------------------ Captured log setup ------------------------------

麻煩幫忙看下

相關文章