• Selenium (1) —— Selenium安装与测试(101 Tutorial)


    Selenium (1) —— Selenium安装与测试(101 Tutorial)


    jvm版本: 1.8.0_65

    selenium版本: v2.48.0 (Standalone Selenium Server)

    参考来源:

    Selenium官方下载

    Use Selenium Grid to enhance testing of web applications

    Homebrew

    安装

    • 安装selenium server

    有brew的童鞋可以很方便的通过命令行安装

    $ brew install selenium-server-standalone
    

    然后运行

    $ selenium-server -port 4444
    

    $ selenium-server -role hub -port 4444	
    

    前一命令默认以单节点方式运行,后一个命令以grid方式运行。

    没有brew的童鞋,可以通过从官方网站下载jar包,然后用java运行

    java -jar selenium-server-standalone-2.48.0.jar -role hub	
    

    本篇我们着重介绍webdriver和以grid方式运行安装与配置。

    • 安装selenium webdriver

    selenium webdriver对多种浏览器都有支持,由于我的测试环境是Mac OS,以下我们主要介绍safari、phantomjs、chrome、firefox、opera这几种浏览器。

    首先我们通过gem命令行安装selenium webdriver

    $ sudo gem install selenium-webdriver
    

    此时会遇到类似以下错误

    “unable to convert "xE0" from ASCII-8BIT to UTF-8 
    for lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so, 
    skipping“
    

    解决方案是加上命令参数

    $ sudo gem install selenium-webdriver --no-document
    

    如果ruby被墙了,大家可以自行切换ruby source

    $ gem sources --remove https://rubygems.org/
    $ gem sources -a https://ruby.taobao.org/
    

    安装完毕后,我们尝试启动各个webdriver并且将其注册到selenium server hub上。

    注意在启动注册之前,我首先要启动selenium server hub。

    $ selenium-server -role hub -port 4444	
    

    测试

    分别为几种不同的浏览器指定端口

    • [1231]-safari

        $ selenium-server -role node -hubHost localhost -hubPort 4444 -browser "browserName=safari,setjavascriptEnabled=true,acceptSslCerts=true,maxInstances=5,Platform=MAC" -port 1231
      

      maxInstances=5 表示有5个实例

    • [1232]-phantomjs

        $ selenium-server -role node -hubHost localhost -hubPort 4444 -browser "browserName=phantomjs,setjavascriptEnabled=true,acceptSslCerts=true,maxInstances=4,Platform=MAC" -port 1232
      
    • [1233]-chrome

        $ selenium-server -role node -hubHost localhost -hubPort 4444 -browser "browserName=chrome,setjavascriptEnabled=true,acceptSslCerts=true,maxInstances=2,Platform=MAC" -port 1233
      
    • [1234]-firefox

        $ selenium-server -role node -hubHost localhost -hubPort 4444 -browser “browserName=firefox,setjavascriptEnabled=true,acceptSslCerts=true,maxInstances=4,Platform=MAC" -port 1234
      
    • [1235]-opera

        $ selenium-server -role node -hubHost localhost -hubPort 4444 -browser "browserName=opera,setjavascriptEnabled=true,acceptSslCerts=true,maxInstances=2,Platform=MAC" -port 1235	
      

    启动注册完毕后,我们可以通过http://localhost:4444/grid/console查看各个浏览器代理的状态

    结束

  • 相关阅读:
    POJ 3348 Cows (凸包面积)
    P4126 [AHOI2009]最小割
    P1903 [国家集训队]数颜色
    P3749 [六省联考2017]寿司餐厅
    CF666E Forensic Examination
    P2336 [SCOI2012]喵星球上的点名
    P1117 [NOI2016]优秀的拆分
    P3747 [六省联考2017]相逢是问候
    CF1062F Upgrading Cities
    P3243 [HNOI2015]菜肴制作
  • 原文地址:https://www.cnblogs.com/richaaaard/p/5097792.html
Copyright © 2020-2023  润新知