2

I have a situation where we would like to run our Selenium test suite, but at certain points in the process we would like to execute a shell command on our machine.

Does Selenium have the capability of executing a shell command and to receive a response and then to act on those results? Is this possible? If so, how? thanks in advance.

Rajat
  • 29
  • 1
  • 2

3 Answers3

2

You tagged it TestNG meaning you write your Selenium tests in Java. The Selenium framework itself does not have a method to run shell scripts. But Java does, you can just execute commands in your tests and later use the output or input from/for Selenium actions.

Runtime.getRuntime().exec()

Read more:

Niels van Reijmersdal
  • 2,038
  • 1
  • 20
  • 36
0

Selenium is just a library for interacting with web browsers. To strictly answer your question.. the answer is "No, it can not". However, you can easily integrate execution of shell scripts from your test code or framework. How you do that will depend on the language you are using.

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
0

Yes you can, but you have to use certain specific libraries along with it in addition to the language you choose eg. If you choose java, you either have to provide repo url via maven or gradle but if you just use python instead since it's highly interpreted, it can pull dynamic content that do pose limitation in Java Selenium, TestNG, PDFBox, POI lib etc. You can deploy a js library of your choice and include that function inside your python code to be invoked via the commands or action that you set your application to.

In short, use Python for purely less troubling dynamic meta extractions, string manipulation, piping output to any other file. Hope that helps.