Install Google Chrome on AWS EC2 Linux 2 for Selenium TestingStep by Step Guaide

To install Google Chrome on an AWS EC2 instance running Amazon Linux 2, follow these steps. This will allow you to use Chrome for Selenium testing.

Step 1: Update the System

bash

Copy code

sudo yum update -y

For Assistance 

Step 2: Add Google Chrome Repository

Create a repository file for Google Chrome:

bash

Copy code

sudo nano /etc/yum.repos.d/google-chrome.repo

Add the following content to the file:

bash

Copy code

[google-chrome]

name=google-chrome

baseurl=https://dl.google.com/linux/chrome/rpm/stable/x86_64

enabled=1

gpgcheck=1

gpgkey=https://dl.google.com/linux/linux_signing_key.pub

Save the file (Ctrl+O, then Enter) and exit (Ctrl+X).

Step 3: Install Google Chrome

Install Google Chrome using the following command:

bash

Copy code

sudo yum install -y google-chrome-stable

Step 4: Verify Chrome Installation

To check if Chrome is installed successfully:

bash

Copy code

google-chrome –version

Step 5: Install Dependencies for Chrome

Ensure all dependencies required for Chrome to run are installed:

bash

Copy code

sudo yum install -y atk cups-libs libX11 libXcomposite libXcursor libXdamage libXext libXi libXrandr libXScrnSaver libXtst pango alsa-lib

Step 6: Install ChromeDriver

  1. Download ChromeDriver:
    Check the Chrome version installed and download the matching ChromeDriver version:

bash

Copy code

google-chrome –version

Visit the ChromeDriver Downloads page and note the version matching your Chrome version.

Example (replace VERSION with the matching version):

bash

Copy code

wget https://chromedriver.storage.googleapis.com/VERSION/chromedriver_linux64.zip

  1. Extract ChromeDriver:

bash

Copy code

unzip chromedriver_linux64.zip

  1. Move ChromeDriver to a PATH directory:

bash

Copy code

sudo mv chromedriver /usr/local/bin/

  1. Verify ChromeDriver Installation:

bash

Copy code

chromedriver –version

For Assistance 

Step 7: Configure Selenium

Ensure Selenium is installed in your Python environment:

bash

Copy code

pip install selenium

Step 8: Test Selenium with Chrome

Here’s a sample Python script to verify Selenium and Chrome integration:

python

Copy code

from selenium import webdriver

 

options = webdriver.ChromeOptions()

options.add_argument(‘–headless’)  # Run Chrome in headless mode

options.add_argument(‘–no-sandbox’)

options.add_argument(‘–disable-dev-shm-usage’)

 

driver = webdriver.Chrome(options=options)

driver.get(“https://www.google.com”)

print(“Page Title is:”, driver.title)

 

driver.quit()

Run the script:

bash

Copy code

python3 your_test_script.py

Troubleshooting

  • If Chrome fails to start, ensure –no-sandbox and –disable-dev-shm-usage options are used, as these are needed for environments like EC2.
  • Use a lightweight EC2 instance type (e.g., t3.medium) to handle Chrome dependencies efficiently.

For Assistance 

Share