Last active
March 14, 2022 13:05
-
-
Save smurugap/1faac136e898b47fe851ae1bbd56e96b to your computer and use it in GitHub Desktop.
Selenium grid installation and testing (python) with chrome on ubuntu 16.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ubuntu Desktop environment: | |
* apt-get update && sudo apt-get upgrade | |
* apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal | |
Setup VNC server environment: | |
* apt-get install vnc4server | |
* adduser sanity (passwd: c0ntrail123) | |
* usermod -G sudo sanity | |
As user sanity do the below | |
* vncserver | |
* vncserver -kill :1 | |
* cat ~/.vnc/xstartup | |
#!/bin/sh | |
# Uncomment the following two lines for normal desktop: | |
# unset SESSION_MANAGER | |
# exec /etc/X11/xinit/xinitrc | |
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup | |
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources | |
xsetroot -solid grey | |
vncconfig -iconic & | |
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & | |
x-window-manager & | |
# Append the below lines to the xstartup | |
gnome-panel & | |
gnome-settings-daemon & | |
metacity & | |
nautilus & | |
Selenium Grid: | |
Install google chrome(any means) and chrome driver. | |
21 wget https://chromedriver.storage.googleapis.com/2.45/chromedriver_linux64.zip | |
27 unzip chromedriver_linux64.zip | |
29 sudo cp chromedriver /usr/bin/ | |
30 sudo chown root:root /usr/bin/chromedriver | |
31 sudo chmod +x /usr/bin/chromedriver | |
Install selenium server | |
Download from https://www.seleniumhq.org/download/ | |
Start hub and node from inside the vnc session: | |
hub: | |
java -jar selenium-server-standalone-3.141.59.jar -role hub -port 4444 -host 10.84.7.29 | |
nodes: | |
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://10.84.7.29:4444/grid/register/ | |
Python interface: | |
pip install selenium | |
Test script to validate parallel execution: | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.chrome.options import Options | |
chrome_options = Options() | |
chrome_options.add_argument("--incognito") | |
driver1 = webdriver.Remote( | |
command_executor="http://10.84.7.29:4444/wd/hub", | |
desired_capabilities={ | |
"browserName": "chrome", | |
}, | |
options=chrome_options) | |
driver2 = webdriver.Remote( | |
command_executor="http://10.84.7.29:4444/wd/hub", | |
desired_capabilities={ | |
"browserName": "chrome", | |
}, | |
options=chrome_options) | |
try: | |
driver1.implicitly_wait(30) | |
driver2.implicitly_wait(30) | |
driver1.set_window_position(0,0) | |
driver1.set_window_size(600,600) | |
driver2.set_window_position(0,0) | |
driver2.set_window_size(600,600) | |
driver1.get("http://www.python.org") | |
assert "Python" in driver1.title | |
driver2.get("http://www.google.com") | |
elem1 = driver1.find_element_by_name("q") | |
elem2 = driver2.find_element_by_name("q") | |
elem1.send_keys("documentation") | |
elem2.send_keys("webdriver") | |
elem1.send_keys(Keys.RETURN) | |
elem2.send_keys(Keys.RETURN) | |
assert "No results found." not in driver1.page_source | |
finally: | |
import time; time.sleep(30) | |
driver1.quit() | |
driver2.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment