zoukankan      html  css  js  c++  java
  • SilkTest天龙八部系列7-动态对象识别

    在测试web应用时,我们常常需要面对web页面对象变化频繁,并且使用预定义方式识别对象慢的困难。为了解决这些问题,SilkTest引入了dynamic object recognition技术,它使用xpath来查找和识别界面上的对象。它可以使用Find和FindAll方法来识别这些对象,从而避免了在页面更改后不得不频繁改变frame.inc的问题。下面我用一个简单的项目来演示一下如何使用dynamic object recognition技术来测试borland提供的web gmo应用。
    1. 新建一个xbrowser的project名为gmo
    2. 打开IE输入我们要测试的web页 http://demo.borland.com/gmopost/
    3. 在silktest中,点击工具栏上的enable extensions,在出现的enable extensions对话框中,选择iexplorer应用的Welcome to Green Mountain Outpost条目。 silktest会自动为其选中win32和xbrowser等extensions功能,你需要点击"enable extensions"按钮来激活它。然后点击close按钮关闭该对话框。
    4. 点击basic workflow工具栏上的set recovery system按钮为系统设置一个appstate GMO。这是silktest会自动为你生成一个frame.inc文件,内容如下所示:

     

    [ ] const wMainWindow = InternetExplorer
    [ ]
    [-] window BrowserApplication InternetExplorer
    [-]  multitag TAG_IS_OPEN_AGENT
    [ ]  "InternetExplorer"
    [ ]
    [ ] // The working directory of the application when it is invoked
    [ ]  const sDir = "C:/Documents and Settings/ZengYuetian/桌面"
    [ ]
    [ ] // The command line used to invoke the application
    [ ]  const sCmdLine = """C:/Program Files/Internet Explorer/iexplore.exe"" "
    [ ]
    [ ] // The first window to appear when the application is invoked
    [ ] // const wStartup = ?
    [ ]
    [ ] // The list of windows the recovery system is to leave open

    [ ] // const lwLeaveOpen = {?}
    [ ]

    5.现在你需要手工加入一个appstate GMO
    [-] appstate GMO() basedon DefaultBaseState
    [ ] window browser = InternetExplorer.Find(".//BrowserWindow")
    [ ] browser.navigate("http://demo.borland.com/gmopost/")
    它的意义在于运行这个appstate会让浏览器自动导航至待测web页面http://demo.borland.com/gmopost/。同时我们还应该注意到其第二行中使用了Find函数来查找一个XPath为.//BrowserWindow的控件,该控件并未在我们的frame.inc中声明,这就是dynamic object recognition技术和通常我们用的先定义控件后使用的方法最大不同。

    6. 新建一个testcase文件gmo_test.t,用record菜单下面的window identifiers来识别页面上的enter GMO online按钮,这个时候你会采集到如下的dynamic object recognition ".//DomButton[@language='JavaScript' and @type='button' and @name='bSubmit' and @value='Enter GMO OnLine']",这个就是该按钮的的XPath,我们并不需要所有的内容,只需要能够唯一标识该按钮的一部分内容,这里我们选择.//DomButton[@name='bSubmit']即可。

    7. 在gmo_test.t中输入下面的内容,该测试用例用来进入gmo online page

    [-] testcase goto_online() appstate GMO
    [ ] window browser = InternetExplorer.find(".//BrowserWindow")
    [ ] browser.find(".//DomButton[@name='bSubmit']").click()

    8. 运行一下,看看测试用例是否带我们进入了http://demo.borland.com/gmopost/online-catalog.htm页面

  • 相关阅读:
    # 机器学习算法总结-第七天(线性回归)
    # 机器学习算法总结-第六天(Adaboost算法)
    # 机器学习算法总结-第五天(降维算法PCA/SVD)
    #再谈 CVE-2017-10271回显POC构造
    # 机器学习算法总结-第四天(SKlearn/数据处理and特征工程)
    # 机器学习算法总结-第三天(支持向量机)
    # 机器学习算法总结-第二天(朴素贝叶斯、逻辑回归)
    # 机器学习算法总结-第一天(KNN、决策树)
    # weblogic CVE-2019-2615/2618(任意文件读取,任意文件上传)
    # CVE-2019-2725二次反序列化EventData Gadget POC/JdbcRowSetImpl POC构造
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3295271.html
Copyright © 2011-2022 走看看