本文介绍了如何通过Selenium-side-runner为Zalenium消息向在网格中运行的Selenium IDE测试中添加cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经记录了使用Selenium IDE进行的测试,并且正在将生成的.side文件提交给selenium-side-runner以在使用Zalenium构建的Selenium Grid上运行.是否可以运行从提交到selenium-side-runner的测试中调用driver.manage().addCookie()的命令?我想这样做是将测试进度和状态信息发送回Zalenium

I've recorded a test using Selenium IDE and am submitting the generated .side file to selenium-side-runner to run on a Selenium Grid built using Zalenium. Is it possible to run a command that calls driver.manage().addCookie() from the test that was submitted to selenium-side-runner? I want to do this to send messages back to Zalenium with test progress and status

我向Selenium IDE编辑器添加了命令executeScript,目标为driver.manage().addCookie({name: 'test', value: 'test'})

I added a command executeScript to the Selenium IDE editor with a target of driver.manage().addCookie({name: 'test', value: 'test'})

我看到commons.js中selenium-side-runner生成的命令是

I see that the command that selenium-side-runner generated in commons.js was

await driver.executeScript(`driver.manage().addCookie({name:'test', value: 'test'});`);

这样做会导致浏览器报告错误JavascriptError: javascript error: driver is not defined

Doing this causes the browser to report an error JavascriptError: javascript error: driver is not defined

我认为我需要的是无需driver.executeScript包装器即可生成的代码.有没有一种方法可以将我的Selenium IDE测试导出到NUnit?

I think what I need is the code to be generated without the driver.executeScript wrapper. Is there a way to accomplish this without exporting my Selenium IDE test to NUnit?

推荐答案

我能够通过在Windows开发人员机器上粗略地修改selenium-side-runner软件包来使此功能正常工作

I was able to make this functionality work by crudely modifying the selenium-side-runner package on my Windows dev machine

在文件~\node_modules\selenium-side-runner\node_modules\selianize\dist\selianize.cjs.js

更改

function generateScript(script, isExpression = false) {
  return `await driver.executeScript(\`${isExpression ? `return (${script.script})` : script.script}\`${script.argv.length ? ',' : ''}${script.argv.map(n => `vars["${n}"]`).join(',')});`;
}

function generateScript(script, isExpression = false) {
  if (script.script.indexOf('zalenium') > -1)
  {
    return script.script;
  } else 
  {
    return `await driver.executeScript(\`${isExpression ? `return (${script.script})` : script.script}\`${script.argv.length ? ',' : ''}${script.argv.map(n => `vars["${n}"]`).join(',')});`;
  }
}

现在,当使用selenium-side-runner运行测试时,调用"executeScript".任何包含zalenium的值将在测试脚本中逐字生成命令

Now when running a test with selenium-side-runner, calling "executeScript" with any value that contains zalenium will generate the command verbatim in the test script

这篇关于如何通过Selenium-side-runner为Zalenium消息向在网格中运行的Selenium IDE测试中添加cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:57