• Selenium Video Tutorials

Selenium IDE - Emitting Code



Selenium IDE is an important tool used extensively for its record and play back feature. It comprises of two critical components namely playback within the browser using the actions and events and playback using the command-line mode with the help of the command-line runner.

Selenium SIDE Runner Environment

The Selenium runner is built on Node. This can be used for emitting the code. The other requirements include −

  • Node.js Version 8 and the Above Versions
  • Jest
  • Jest Environment Selenium
  • Selenium Webdriver

How to Emit Code?

While emitting the code, certain measures need to be taken care of. As the plugins are not the only ones that are emitting the code. It also does not take care of the flow of emissions. To confirm that the plugins do not interfere in each other’s execution, certain measures are taken −

Avoid Using Return

The code after the usage of return keyword is never executed and stop the working of other plugins. For example,

return promise1();
plugin1func(); // after the usage of above return code, this is unreachable.

Instead the below solution with the await function works −

await promise1();
plugin1func(); // this should work

Avoid Defining Variables Globally

Defining variables at the global level points to the fact that if another plugin or Selenium IDE has defined the same variable, either an error message will be generated or make debugging difficult. For example,

  • store | button | ele
  • plugin click | button
  • assert element present | xpath=${ele}

On defining the variable, the code will be −

let ele = "button";
let ele = await driver.findElement();
await ele.click();
expect(ele).toBePresent(); // ambiguity on which variable

Instead the below solution with the then function of Promise works −

let ele = "button";
await driver.findElement().then(ele => {
  return ele.click();
});
expect(ele).toBePresent(); // hold the correct defined button

Conclusion

This concludes our comprehensive take on the tutorial on Selenium IDE - Emitting Code. We’ve started with describing Selenium SIDE Runner Environment, and How to emit code. This equips you with in-depth knowledge of the Selenium IDE Emitting Code. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements