windows-docker-selenium环境搭建

2017-07-13  本文已影响13人  望月成三人
Paste_Image.png
docker@default:~$ sudo -i
Boot2Docker version 17.06.0-ce-rc5, build HEAD : 97c1118 - Tue Jun 20 22:29:34 UTC 2017
Docker version 17.06.0-ce-rc5, build b7e4173
root@default:~# 
sudo sed -i "s|EXTRA_ARGS='|EXTRA_ARGS='--registry-mirror=https://jjvitjcg.mirror.aliyuncs.com |g" /var/lib/boot2docker/profile
sudo -i vi /etc/resole.conf
nameserver 8.8.8.8
FROM selenium/node-chrome
USER root
RUN apt-get update \
    && apt-get -y install ttf-wqy-microhei ttf-wqy-zenhei \
    && apt-get clean

进入到Dockerfile目录,用命令:docker build -t debug/chinese .
查看镜像:

image.png

设置docker-compose.yaml,并启动

--- 
chrome: 
  image: chinese_chrome
  links: 
    - hub
  ports: 
    - "5902:5900"
  environment: 
    - NODE_MAX_INSTANCES=30
    - NODE_MAX_SESSION=30
    - NODE_REGISTER_CYCLE=5000
    - DBUS_SESSION_BUS_ADDRESS=/dev/null
  volumes:
    - /dev/shm:/dev/shm
firefox52: 
  image: "baozhida/selenium-node-firefox:52"
  links: 
    - hub
  ports: 
    - "5903:5900"
  environment: 
    - NODE_MAX_INSTANCES=30
    - NODE_MAX_SESSION=30
    - NODE_REGISTER_CYCLE=5000
    - DBUS_SESSION_BUS_ADDRESS=/dev/null
  volumes:
    - /dev/shm:/dev/shm
firefox51: 
  image: "baozhida/selenium-node-firefox:51"
  links: 
    - hub
  ports: 
    - "5901:5900"
  environment: 
    - NODE_MAX_INSTANCES=30
    - NODE_MAX_SESSION=30
    - NODE_REGISTER_CYCLE=5000
    - DBUS_SESSION_BUS_ADDRESS=/dev/null
  volumes:
    - /dev/shm:/dev/shm
hub: 
  image: selenium/hub
  ports: 
    - "4444:4444"


启动的时候千万别忘了设置环境变量来控制hub和node的参数,不然crash问题特别严重 ,这个问题确实是要在docker-compose里设置一下。 主要是就是多个node和浏览器一起跑的时候内存利用不当的问题。 挂载并共享宿主机的/dev/shm 能有效解决这个问题

docker-compose up

Paste_Image.png image.png image.png

配置本地调试

node-chrome-debug: 
  image: selenium/node-chrome-debug
  links: 
    - hub
  ports: 
    - "5900:5900"
Paste_Image.png Paste_Image.png image.png

输入查看images:

image.png

问题点总结:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="WEBUIAUTO" parallel="tests" thread-count="4">
<!-- browserversion 48.0.2564.109 50.0.2661.75 172.30.232.132 58.0.3029.81 192.168.99.100  55.0.2883.75-->
    <test name="chrome48">
        <parameter name="browsertype" value="chrome" />
        <parameter name="browserversion" value="48.0.2564.109" />
        <parameter name="remoteIP" value="192.168.99.100" />
        <classes>
            <class name="com.tn.automation.testngcase.RunCase" />
        </classes>
    </test>

    <test name="chrome58">
        <parameter name="browsertype" value="chrome" />
        <parameter name="browserversion" value="58.0.3029.81" />
        <parameter name="remoteIP" value="192.168.99.100" />
        <classes>
            <class name="com.tn.automation.testngcase.RunCase" />
        </classes>
    </test>
@BeforeTest
    @Parameters({ "browsertype", "browserversion", "remoteIP" })  
    public void setUp(String browsertype, String browserversion, String remoteIP) throws Exception {
        .....
    }
    

    @Test
    public void case_001() throws Exception {
        driver.open("http://bj.tuniu.com");
        Thread.sleep(5000);
        //具体测试信息
        
    }
    
class SeleniumClass:
    @BeforeMethod(description="Prepare test Enviroment.")
    def before(self):
        preporter.info("set up driver")
        browser = config.get_property("browser")
        if browser == "firefox":
            self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                                           desired_capabilities=DesiredCapabilities.FIREFOX)
        elif browser == "chrome":
            self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                                           desired_capabilities=DesiredCapabilities.CHROME)


    def test1(self):
        preporter.info("start to test")
        self.driver.get("http://www.baidu.com")

上一篇 下一篇

猜你喜欢

热点阅读