使用远程 Web 测试框架BrowserStack 和 LamdaTest时,Chrome 上的表单输入条目失败

问题描述

我的测试套件在本地以及使用 Chrome 的 gitlab 管道中都可以正常工作。

但是,在远程测试框架上使用 Chrome(仅)运行它们时,它们会直接在登录页面上失败。
我测试了 browserstack 和 LamdaTest,当我尝试在表单输入字段中输入文本时,它们都失败了。

错误信息是:

{"sessionId":"d6c0edadf898c18d38e9dda073a868fa","status":61,"value":{"message":"invalid argument: 'value' must be a list\n (Session info: chrome=80.0.3987.87)\n (Driver info: chromedriver=80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}),platform=Windows NT 10.0.14393 x86_64)"}}

相同的测试适用于 Safari 和 Firefox,只有 Chrome 失败。 我花了一些时间与 LambdaTest 的人一起调查,似乎在使用“常规”硒选择器和动作时一切正常,但只有空手道失败。
有没有人遇到过同样的问题?

编辑:添加Prateek Singh 提供的非空手道网络驱动程序负载

Request POST http://hub.lambdatest.com /wd/hub/session/719c9157598420fb3e272f53be31ab51/elements  
   { using: 'css selector',value: 'input[type=text]' }

Response 200 POST http://hub.lambdatest.com/wd/hub/session/719c9157598420fb3e272f53be31ab51/elements (461ms)
   {
     sessionId: '719c9157598420fb3e272f53be31ab51',status: 0,value: [ { ELEMENT: '0.37079523975334916-2' } ]
   }
   
Request POST http://hub.lambdatest.com /wd/hub/session/719c9157598420fb3e272f53be31ab51/element/0.37079523975334916-2/value  
   {
     value: [
       'L','a','m','b','d','T','e','s','t','\n'
     ]
   }

Response 200 POST http://hub.lambdatest.com/wd/hub/session/719c9157598420fb3e272f53be31ab51/element/0.37079523975334916-2/value (1366ms)
   {
     sessionId: '719c9157598420fb3e272f53be31ab51',value: null
   }

解决方法

尝试使用最新的 selenium 版本,添加以下功能:

caps.setCapability("browserstack.selenium_version","3.141.59");
,

您的远程提供商似乎不符合 chromedriverW3C spec。例如,对 /element 调用的响应应该是这样的,我知道您使用过 elements,但您可以看出响应“形状”是针对旧的不合规的 chrome 驱动程序:

3 > POST http://localhost:9515/session/87ff90ad57ad432540b413740a66f7c1/element
3 > Content-Type: application/json; charset=UTF-8
3 > Content-Length: 43
3 > Host: localhost:9515
3 > Connection: Keep-Alive
3 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_231)
3 > Accept-Encoding: gzip,deflate
{"using":"css selector","value":"#inputId"}

20:59:25.475 [main] DEBUG com.intuit.karate - response time in milliseconds: 9
3 < 200
3 < Content-Length: 88
3 < Content-Type: application/json; charset=utf-8
3 < cache-control: no-cache
{"value":{"element-6066-11e4-a52e-4f735466cecf":"d7bdd4a1-17bc-4ee0-817b-cf7052641d25"}}

element/value 的请求肯定是错误的,这是一个符合规范的请求示例,其中参数 text 应在有效负载中(不是 value 下的数组) ):

4 > POST http://localhost:9515/session/87ff90ad57ad432540b413740a66f7c1/element/d7bdd4a1-17bc-4ee0-817b-cf7052641d25/value
4 > Content-Type: application/json; charset=UTF-8
4 > Content-Length: 22
4 > Host: localhost:9515
4 > Connection: Keep-Alive
4 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_231)
4 > Accept-Encoding: gzip,deflate
{"text":"hello world"}

20:59:25.560 [main] DEBUG com.intuit.karate - response time in milliseconds: 83
4 < 200
4 < Content-Length: 14
4 < Content-Type: application/json; charset=utf-8
4 < cache-control: no-cache
{"value":null}

这一定是其他浏览器可以工作的原因——也许是因为您的 LambdaTest 设置使用的是旧版本的 chrome 驱动程序。空手道将不支持旧版本,但如果适用,我们很乐意修复与 W3C 标准的任何差距。

作为参考,这些是我使用的 chrome-driver 返回的功能:

{
   "value":{
      "capabilities":{
         "networkConnectionEnabled":false,**"chrome":{
            "chromedriverVersion":"87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs\/branch-heads\/4280@{#1761})","userDataDir":"\/var\/folders\/py\/d2vyrn2n3bz7yzp7rppntw7cvsmbgv\/T\/.com.google.Chrome.JJHuOI"
         },"acceptInsecureCerts":false,"browserVersion":"87.0.4280.141","browserName":"chrome","platformName":"mac os x","setWindowRect":true,"webauthn:virtualAuthenticators":true
      },"sessionId":"87ff90ad57ad432540b413740a66f7c1"
   }
}