Selenium Grid の使い方


Arch Linux でのインストール

yay -S selenium-server-standalone

1) Hub の起動

java -jar /usr/share/selenium-server/selenium-server-standalone.jar  -role hub

ブラウザーで http://192.168.8.100:4444/grid/console にアクセス

2) ひとつめの Node の起動

java -jar /usr/share/selenium-server/selenium-server-standalone.jar  -role node

ブラウザーで http://192.168.8.100:4444/grid/console にアクセス

3) ふたつめの Node の起動

java -jar /usr/share/selenium-server/selenium-server-standalone.jar  -role node

ブラウザーで http://192.168.8.100:4444/grid/console にアクセス

テストスクリプト

Python3 で、FireFox を使います。

grid_follow_link.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   grid_follow_link.py
#
#               Oct/16/2018
#
# ------------------------------------------------------------------
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

url = 'https://ekzemplaro.org'

driver = webdriver.Remote(
    command_executor='http://192.168.8.100:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.FIREFOX)
driver.get(url)

tag = driver.find_element_by_id('ekzemplaro')
tag.click()
#
tag = driver.find_element_by_link_text('English')
tag.click()
#
# ------------------------------------------------------------------