zoukankan      html  css  js  c++  java
  • c/s端测试——nw.js篇(selenium工具)

    最近在为兄弟部门开发自动化测试工具。
    然后才知道现在竟然有JS工具可以把JS打包成cs端程序了,太牛了,js发展是真快。并且还是跨平台的,mac、windows、linux都支持。
    当然,今天不是说nw.js是怎样去打包EXE程序,今天是来说怎么去对这样的nw.js打包的C/S程序进行自动化测试。
    百度了很久,没找到对应的资料,还是打开vps谷歌了一把,以下基本都是官网的内容

    一、工具ChromeDriver

    ChromeDriver , 一款开源工具 , 提供跨浏览器自动测试页面应用 . 提供引导页面 , 用户输入 , 脚本执行等功能 . 实现Chromium协议的独立服务 . 安卓系统以及PC系统(Mac, Linux, Windows, ChromeOS)的Chorme浏览器中可以运行

    NW.js提供自定义ChromeDriver完成自动测试基于NW.js开发的应用 , 可以通过类似于selenium工具进行使用

    二、安装

    1.从官网下载SDK构建方式的NW.js , 其中包含ChromeDriver工具 .

    解压下载的文件,chromedriver在解压的NW.js目录中

    Linux系统中名为nw

    Windows系统中名为nw.exe

    Mac系统中名为node-webkit.app

    将开发的dist文件替换到sdk中,若有相应的配置文件同样放在其根目录下
    

    然后打开nw.exe,点击主页面,右键点击,可选择“检查”、F12,效果与打开浏览器一致,如下:

    001

    002

    2.安装selenium-python到python环境中 :

       pip install selenium
    

    三、运行

    假设你的应用远程查询内容 . 页面代码大致如下:

    <form action="http://mysearch.com/search" method="GET">
    	    <input type="text" name="q"><input type="submit" value="Submit">
    </form>
    

    编写一个python脚本自动填充搜索框并提交表单:

    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    path = 'D:\项目\测试平台\nw\nw_sdk\'
    chrome_options.add_argument("nwapp="+path)
    
    driver = webdriver.Chrome(executable_path=path+'chromedriver', chrome_options=chrome_options)
    
    time.sleep(5) # 等待5秒 , 查看页面
    search_box = driver.find_element_by_name('q')
    search_box.send_keys('ChromeDriver')
    search_box.submit()
    time.sleep(5) # 等待5秒 , 查看搜索结果
    driver.quit()
    

    参考http://selenium-python.readthedocs.org/详细文档 .

    四、修改参数

    被修改的chromedriver工具默认在NW可执行相同目录下 .

    如果需要传递参数给命令行 , 需要使用选项nwargs:

    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    chrome_options.add_argument("nwapp=/path/to/your/app")
    chrome_options.add_experimental_option("nwargs", ["arg1", "arg2"])
    
    driver = webdriver.Chrome(executable_path='/path/to/nwjs/chromedriver', chrome_options=chrome_options)
    

    四、最后

    忘记放官网链接了

    https://nwjs-cn.readthedocs.io/zh_CN/latest/Base/Advanced/Test%20with%20ChromeDriver/index.html#_1

  • 相关阅读:
    Apollo 配置中心
    Sentinel 限流
    soul 网关
    xxl-job 任务管理
    java Young GC排查
    bitmap(位图)
    RabbitMQ一个简单可靠的方案(.Net Core实现)
    从技术角度讨论微服务
    你可能不知道的.Net Core Configuration
    浅谈开发模式及架构发展
  • 原文地址:https://www.cnblogs.com/yaomaomao/p/10274506.html
Copyright © 2011-2022 走看看