Execute scripts on remote node (selenium grid node) from the local

Hello All

what or how can I execute python or javascript files living in the selenium remote node (Selenium Grid) from the local by using only SeleniumLibrary

Here is some context

I was asked to work on a robotframework project that runs on GitHub/docker and connects to SauceLabs (as a selenium grid) and I need to find a way to persist data/files/folders from one test run to another.

Important points

  1. I cannot use other libraries that are not SeleniumLibrary or AppiumLibrary (it will be difficult to get the approval of any custom library).
  2. SauceLabs has a Storage service and easy-to-use API to upload and download files.
  3. SauceLabs has a pre-run function that allows the execution of a file to prepare the VM/Node before the test case starts.

My idea:

  1. I need to find a way to send files from my local to the selenium remote node :white_check_mark:
  2. I need to find a way to execute either a python script / shell script on the remote node, the script will zip a folder in the remote and later upload it to sauce labs storage. :question:

Questions you might have so far.

Why don’t you use choose file from SeleniumLibrary? Because Choose file is waiting for a locator and a file. I couldn’t find a way to use this keyword without the locator. So pre-run solution seems the way from local->remote I need to figure out the remote->local.
Use a daemon, Ummm I thought about it, but in order to start the test case ( or open the browser) the pre-run step must finish, so either I end with a daemon that stops before the test case start or an orphan one (which I have no idea how to deal with).

Now Where I’m stuck

How can I:

  • Execute a python file on the remote node file system? (I put the script there with the pre-run, and it is just a small script that will zip a directory and use saucelabs API to send it to saucestorage)
  • if the above is not possible, can I use the execute javascript keyword to target the filesystem in the selenium remote node?

PS. :slight_smile: no pressure, I will be fired if I cannot find the way to do this, no pressure … :cry: :cry:

An update.

I couldn’t find a way to execute python scripts by using execute javascript
I wanted to be able to extract files from a sauce labs VM, those files will be the product of the test case or for example, the user-data-dir from chrome or chromium edge.
I decided to do as follow:

  1. I create a form on the flask, and I used to upload directories
  2. The Flask server will get this directory, zip it and send it to storage.

Now few extra details:

  1. I use docker-compose
  2. one service will be the Flask server using gunicorn for the webserver
  3. the second service will be Ngrok to expose the server to the public
  4. On the Robot framework, I made a custom keyword that will query the NGrok API to get the public URL for the flask server
  5. In the test case I use chose file to upload the directory from the sauce VM.

Hi Victor,

Read this:

execute javascript as it’s name suggests is for javascript not python, more specifically it tells the browser to execute some javascript in the current page.

I should also not that browsers don’t know how to execute python, they only can execute javascript (or more accurately ECMAScript )

  • The BuiltIn Evaluate will execute simple 1 line python
  • The Run Process keyword could be used for executing a python script from the command line, though all you’ll get back is what you can read from stdout or a file written by the python script
  • A better option for your case might be to create your own test library of keywords in python ( Supported programming languages )
  • another option is rather than writing a python script just combine keywords to achieve what you want to do (assuming you don’t already have the python code), this option might be easier to understand/maintain by other testers in your team down the track

Hopefully this helps,