How to add cookie to Selenium IDE test running in grid via selenium-side-runner for Zalenium messages

和自甴很熟 提交于 2020-08-10 19:32:13

问题


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

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

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

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

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

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?


回答1:


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

In file ~\node_modules\selenium-side-runner\node_modules\selianize\dist\selianize.cjs.js

Change

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(',')});`;
}

to

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(',')});`;
  }
}

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



来源:https://stackoverflow.com/questions/62712675/how-to-add-cookie-to-selenium-ide-test-running-in-grid-via-selenium-side-runner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!