Documentation

    Amazon Web Services

    Microsoft Azure

    RapidAPI

    APILayer

Last Update: 2024-10-22

Selenium Dynamic Grid


Table of Content


Launch Selenium Dynamic Grid
Run test scripts client-side
Connect to your VM via SSH
Deploy files on your VM remotely
Manage Grid Server
Troubleshooting

Launch Selenium Dynamic Grid

Navigate to our listing page on the AWS Marketplace and click 'Continue to Subscribe'.

On the subsequent page, review and accept our terms by selecting 'Accept Terms'.

Once the subscription process is complete, select 'Continue to Configuration'.

Choose the region where you wish to deploy the virtual machine, then click 'Continue to Launch'.

On the final page, select the instance type you wish to use (the recommended instance type is pre-selected) and review the other launch options. Then, click 'Launch'.

After launching, you can view your instance in the EC2 Management Console.

Run test scripts client-side


Note: By default, the Selenium Grid Server is open to the world. You can limit inbound traffic on port 4444 (Selenium) to only your IP address in the AWS Management Console.

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. Note: The first execution after startup is typically very slow, especially on instances with low memory. There is a chance the browser might run out of memory. Performance should improve over time, but consider using an instance with more available memory.

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://<PublicIpAddressOfGridInstance>: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://<PublicIpAddressOfGridInstance>: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://<PublicIpAddressOfGridInstance>: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 see the official documentation for detailed instructions on how to connect to a virtual machine with SSH.

Go to the EC2 Management Console and select the virtual machine to obtain its Public IPv4 address.

Open a Command Prompt / Terminal window and navigate to the directory where your created .pem key file is located. You can connect to your VM with the user 'ubuntu' by executing the following command:

ssh -i <name-of-key-file.pem> ubuntu@<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, using 'ubuntu' as the username.

Click on 'Advanced'.

In the left-side menu, select 'Authentication'. Under Authentication parameters, select the key file you created when you launched the virtual machine. When prompted, convert the .pem key file to PuTTY format.

Close the Authentication window by clicking on 'OK', and connect to the virtual machine by clicking on 'Login'.

Manage Grid Server


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

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

crontab -e

and by removing the last line of that file. Connect to the terminal via SSH and log into user 'ubuntu'.

Troubleshooting

How can I cancel my subscription?

To cancel your subscription, follow these steps:

  1. Go to the AWS Marketplace Console at https://aws.amazon.com/marketplace/library. Ensure that you are logged into the account that is subscribed to the product you want to cancel.
  2. Find the product you want to cancel and click on 'Manage.'
  3. Click on 'Actions' and then select 'Cancel subscription.'

For more detailed instructions, visit the AWS Marketplace Buyer Guide at https://docs.aws.amazon.com/marketplace/latest/buyerguide/cancel-subscription.html.