Documentation
    Amazon Web Services
    Microsoft Azure
    RapidAPI
    APILayer
Last Update: 2024-03-04

Selenium Dynamic Grid


Table of Content


Launch Selenium Dynamic Grid
Run test scripts clientside
Connect to your VM via SSH
Deploy files on your VM remotely
Manage Grid Server

Launch Selenium Dynamic Grid

Navigate to our listings page Selenium Dynamic Grid on Azure Marketplace.

Click on "Get it now" to initiate the launch dialog.

On the "Create a virtual machine" page, enter the username for the virtual machine (e.g., "azureuser"). Set up an SSH key file or use password authentication.

Review the settings and proceed to create the virtual machine.

Run test scripts client side


Note: By default, the Selenium Grid Server is open to the world. You can restrict traffic on port 4444 (Selenium) to only your IP address in the Azure Portal.

Install Selenium libraries in the programming language you wish to use on your local machine. For more information, refer to the official Selenium documentation.

The following sample code shows how you can connect to the instance to run tests on it.

Chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions

options = ChromeOptions()

# Instantiate the WebDriver
driver = webdriver.Remote(
    command_executor='http://<PublicIpAddressOfVM>:4444/wd/hub',
    options=options
)

driver.get("https://www.whatismybrowser.com")
driver.save_screenshot('screenshot.png')
driver.quit()

Firefox:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions

options = FirefoxOptions()

# Instantiate the WebDriver
driver = webdriver.Remote(
    command_executor='http://<PublicIpAddressOfVM>:4444/wd/hub',
    options=options
)

driver.get("https://www.whatismybrowser.com")
driver.save_screenshot('screenshot.png')
driver.quit()

Edge:

from selenium import webdriver

options = webdriver.EdgeOptions()

# Instantiate the WebDriver
driver = webdriver.Remote(
    command_executor='http://<PublicIpAddressOfVM>:4444/wd/hub',
    options=options
)

driver.get("https://www.whatismybrowser.com")
driver.save_screenshot('screenshot.png')
driver.quit()
Connect to your VM via SSH


Please refer to the official documentation for detailed instructions on how to connect to a virtual machine with SSH.

Open a Command Prompt / Terminal window and navigate to the directory where you have saved the .pem key file, which was created in the Azure portal. You can connect to your VM using the username specified during the virtual machine creation process by executing the following command:

ssh -i <name-of-key-file.pem> <username>@<public-ip>

Deploy files on your VM remotely

Download and install WinSCP or any other SCP client of your choice.

Choose 'SFTP' as the file protocol and enter the public IP address of your instance, along with the username you specified when launching the virtual machine.

If you opted for password authentication, enter the specified password. Alternatively, if you wish to use a private key file (.pem) that you generated, you can add it by first clicking 'Advanced' and then selecting 'Authentication' from the left-side menu.

Connect to the virtual machine by clicking on 'Login'.

Manage Grid Server


You can check the actual state of the grid server by opening http://<PublicIpAddressOfGridVM>:4444 in your browser.

The grid server is configured to start at every reboot of the VM. So in case something is broken, try to restart the VM. To remove the automatic startup, remove the installed crontab by

sudo crontab -e

and by removing the last line of that file.