python demo
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
import time
import pytest
class Driver():
hub_url='127.0.0.1:5001/wd/hub'
def chrome(self):
capability=DesiredCapabilities.CHROME
driver=webdriver.Remote(self.hub_url,desired_capabilities=capability)
return driver
def firefox(self):
capability = DesiredCapabilities.FIREFOX
driver = webdriver.Remote(self.hub_url, desired_capabilities=capability)
return driver
class TestBaidu:
def setup(cls):
cls.driver=Driver().chrome()
cls.driver.implicitly_wait(10)
def teardown(self):
time.sleep(5)
self.driver.quit()
def test_baidu(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element('id','kw').send_keys('hogwarts')
self.driver.find_element('id','su').click()
def test_baidu1(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element('id','kw').send_keys('hogwarts')
self.driver.find_element('id','su').click()
def test_baidu2(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element('id','kw').send_keys('hogwarts')
self.driver.find_element('id','su').click()
if __name__ == '__main__':
pytest.main(['-sv','-n','3','test_baidu.py'])
#启动主节点
docker run --name=hub -p 5001:4444 -e GRID_TIMEOUT=0 -e GRID_THROW_ON_CAPABILITY_NOT_PRESENT=true?-e GRID_NEW_SESSION_WAIT_TIMEOUT=-1 -e GRID_BROWSER_TIMEOUT=15000 -e GRID_TIMEOUT=30000 -e GRID_CLEAN_UP_CYCLE=30000 -d selenium/hub:3.7.1-beryllium
# 启动从节点, --link hub指定注册到hub主节点
docker run --name=chrome -p 5902:5900 -e NODE_MAX_INSTANCES=6 -e NODE_MAX_SESSION=6 -e NODE_REGISTER_CYCLE=5000 -e DBUS_SESSION_BUS_ADDRESS=/dev/null -v /dev/shm:/dev/shm --link hub -d selenium/node-chrome-debug:3.7.1-beryllium
默认vnc密码:secret
mac可通过访达连接服务器输入vnc://127.0.0.1:5902连接,输入vnc密码
显示如下页面,可以进行调试查看
非本机指定这两个环境变量:
HUB_PORT_4444_TCP_ADDR
HUB_PORT_4444_TCP_PORT
|