zhaopinboai.com

Remote WebDriver Setup for Browser Automation with Selenium

Written on

Chapter 1: Introduction to Remote WebDriver

In the previous article, we explored the integration of Selenium with the unittest framework. In this concluding installment, we will delve into utilizing WebDriver on a remote server.

Previously, our automation scripts were executed on local machines. However, WebDriver can also operate remotely, allowing you to keep your scripts on your local computer while executing them on a separate remote machine.

A remote WebDriver consists of two main components: the client, which is your code, and the server, a Java servlet.

The architecture overview previously discussed various types of remote WebDriver configurations, which can be summarized as follows:

Diagram of Remote WebDriver Architecture

Let's proceed with a practical example.

Section 1.1: Setting Up the Virtual Machine

For this demonstration, I installed Xubuntu on VirtualBox.

Steps for Configuration:

  1. Create a virtual machine with a minimum of 2 CPUs to prevent errors during the Selenium server execution.
  2. Configure the network adapter to operate in bridged mode.
Screenshot of VM Network Settings
  1. Record the IP address of the machine, which will be used in your script.
Screenshot of VM IP Address
  1. Download the necessary browser WebDriver (in this case, geckodriver) and place it under /usr/local/bin or another location in your system's PATH. More installation details can be found in the previous post.
  2. Obtain the Selenium server JAR file.

Section 1.2: Running the Selenium Server

On the virtual machine (remote server), open two terminals and execute the following commands for both the hub and node, using the version you downloaded:

java -jar selenium-server-4.0.0-beta-3.jar hub

This command will initiate the Selenium Hub, as indicated by the following log output:

18:54:30.877 INFO [UnboundZmqEventBus.] - Sockets created

18:54:30.983 INFO [UnboundZmqEventBus.] - Event bus ready

18:54:33.917 INFO [Hub.execute] - Started Selenium Hub 4.0.0-beta-3 (revision 5d108f9a67): http://192.168.1.39:4444

Next, when you start the node, logs similar to the following will appear:

...java -jar selenium-server-4.0.0-beta-3.jar node

18:54:36.576 INFO [Node.] - Binding additional locator mechanisms: name, id

18:54:37.358 INFO [LocalDistributor.add] - Added node d27ae900-3309-4443-ab19-13fe7340c4e2 at http://192.168.1.39:5555.

18:54:38.082 INFO [GridModel.setAvailability] - Switching node d27ae900-3309-4443-ab19-13fe7340c4e2 (uri: http://192.168.1.39:5555) from DOWN to UP

Section 1.3: Configuring the Local Script

On your local machine, set up your script with the remote machine's IP address noted earlier. By default, port 4444 is used:

driver = webdriver.Remote(

command_executor="http://192.168.1.39:4444",

desired_capabilities=capabilities

)

Finally, execute your script with:

python remote_client_vm.py

Chapter 2: Key Takeaways

It's important to remember that you can utilize WebDriver remotely in a manner similar to local execution. A remote WebDriver is comprised of the client (your code) and the server (the Java servlet).

Steps to Execute:

  • On the remote machine:

    • java -jar selenium-server-x.x.x.jar hub
    • java -jar selenium-server-x.x.x.jar node
  • On the local machine:

    • Configure your script using the command_executor parameter.
    • python your_script.py

I've gained significant insights while studying these topics and have been sharing them for the past eight months. Thank you for following this series!

References

Description: Explore Selenium Browser Automation in Python with this video tutorial that covers the essentials of using Selenium for automated testing.

Description: Dive deeper into Advanced Python Programming for Browser Automation with Selenium in this comprehensive video guide.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

The Google Pixel: Navigating Brand Expectations and Reality

Exploring Google's Pixel brand challenges, balancing high expectations and hardware realities.

How Prisms Separate Light into a Spectrum of Colors

Discover how prisms disperse light into various colors through the principles of physics and light behavior.

Embrace Self-Love: 3 Steps to Nurture Yourself Daily

Discover three actionable steps to cultivate self-love and improve your relationship with yourself while fostering emotional well-being.

Understanding the Reluctance to Seek Help: A Psychological Perspective

This article explores the complex reasons behind the reluctance to seek help, examining psychological, cultural, and societal influences.

Forget the Latest Tech: Embrace the Simplicity of Paper

Explore the benefits of using pen and paper over gadgets for note-taking and productivity.

# The Macronutrient Balance Template: Your Guide to Enhanced Nutrition

Discover how to optimize your nutrition with the Macronutrient Balance Template, designed for achieving your health and fitness goals.

Unlocking Your Purpose: A Journey of Self-Discovery and Growth

Explore the essence of purpose, its significance, and how to navigate your path to fulfillment.

Creating Engaging Content with ChatGPT-4o: 3 Innovative Uses

Discover three surprising ways ChatGPT-4o can enhance your writing and content creation process.