发布新日志

  • QTP基础代码

    2007-12-03 14:14:15

    文章出处:51testing论坛 / 作者:未知 / 发布时间:2006-07-26 / 阅读次数:1363次

           这两周我开始学习QTP测试我们的web服务了;大体的软件使用操作流程是懂了,但具体实施起来特别是代码的组织及函数应用还有一些困难,因为自己只会vb没学习vbscrīpt,所以想和大家交流一下代码等一些基础知识;呵呵,一起学习,加强记忆与应用。

     

    1 生产随机数列
    第一种方法
    randomize'更新反回的数据
    funcation rand(k,n)
    n="int((k-1)*rnd+1) rand=n
    end funcation
    第二种方法
    n="randomnumber.value(1,255)

    2  当运行到表中的某一行,自动导出表中的所有数据
    row=datatable.getcurrentrow
    if row="5" then
      datatable.export("d:\data.xml")
    end if

     

    3 参数化密码
    webedit("txtpass").setsecure"sdsdf...."
    如果参数化密码,可以直接在数据表中写入未加密的密码,它会自动识别,即不用把setsecure改为set

     

    4 如果弹出对话框就获取上面提示信息并与表中的信息对比,不统一证明弹出的提示出错,主要用来验证
    if browser("web_name").dialog("dialog_name").exist(1) then'如果不出现="false     error_message=browser("web_name").dialog("diaglog_name").static("用户密码错误!".getRoproperty("text")
       if error_message<>(datatable.value("error_info"))then
             msgbox(error_message)
          end if
         browser("web_name").dialog("diaglog_name").close
      end if
    这里我总结了两点技巧:
      一是:对于dialog中,虽然提示信息对象名称是"用户密码错误",但如果信息对象名称是“该用户不存在”,不用更改会自动识别,我想主要是录制第一遍时,“用户密码错误”只是让运行时能找到这个控制,而不管它是什么内容,因为在对象仓库中,text不是决定该对象的属性
         二是:如果对于提示信息比较长的,可以用mid(error_message,n,m)取一部份特征提示信息进行验证,这样我想可以节省处理时间,又可以避免长度以及空格等字符的处理

     

    5  datatable.value("num")只在global形式下的一种省略形式;完整形式是:
    datatable.value("num",dtlocalsheet)
    -----向某一列的单元格赋值:
    datatable.value("column_name",dtlocalsheet)="nanjing"
    -----取得某一行具体值:
    datatable.setcurrentrow(n)
    msgbox(datatable.getsheet("global").getparameter("column_name").Rawvalue)
    或者kk=datatable.Rawvalue("column_name","action1")
    ----在run-time时,动态添加表格与数据
    kk=datatable.addsheet("sheet_name").addparameter("column_name","value").name;

     

    7   wintreeview一些操作
    选择一个条目:wintreeview.select(item)'根是0
    根的名称:wintreeview.getitem(0)

     

    8   数据库检查点模块:
    sub database_check
    set con="createobject(""adodb.connection")
    con.open "Descrīption="IBM_ODBC;DRIVER=SQL" Server;SERVER="IBM;UID=sa;""&_
                     "PWD="123456;APP=Quick" Test Pro;WSID="IBM;DATABASE=IBM_table""
    'access方式:con.open "DRIVER="{Microsoft" Access Driver (*.mdb)};DBQ="d:\test.mdb""
    'Orocle方式:con.open "DRIVER="{Oracle" in OraHome92};SERVER="CESHI;UID=CND_TEST;PWD=CND;DBQ=CESHI;DBA=W;APA=T;

    EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BA

    M=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=10;TLO=O;""
    set record="createobject(""adodb.recordset")
    sql="select*from ibm_one_table"
    record.open sql,con
    DO
    if(record("ibm_table_column")="kai")then'//查找表格中有多少kai
    num=num+1;
    end if
    record.movenext
    loop until record.eof="true record.close
    set record="nothing con.close
    set con="nothing end sub

     

    9   换行符
    vbcr----chr(13)回车符// vblf----chr(10)换行符
        vbcrlf----chr(13)+chr(10)结合//type(chr(13)就相当于按了一上键盘上的enter

     

    10  Run from step有两种方式:
    在Keyword View模式会从本步骤运行到所有action结束
    在expert view模式仅会将本action运行结束

     

    11  由于对象属性原因,无法识别对象
    -----对于对象属性是变化的,可以参数化/或者用正则表达式
    -----报匹配多个对象错误,可以spy查看对象,添加一个该对象另一个唯一标识属性
    -----有时可以删除对象的变化的属性来解决识别问题
    ------对于多个完全相同的对象,可以采用添加index,location,createtime等特殊属性来识别
      (index:按照程序源码,绘制对象的先后标识对象,所以与其它相同对象是相互依赖,当其它对象发生
      变化后,原先的所有对象index属性要发生变化,开始是0;如index:="0;         location:根据对象的位置进行确定,从上到下,从左到右;
      CreateTime:按照对象被浏览器打开的先后标识对象)
    ------另外换一种思维方式,采取等效的方法;比如用键盘代替鼠标或用操作系统本身特性去解决问题

     

    12  对系统文件的操作
    -------从系统的文件中获取信息及删除文件
      get_file_infor("c:\she.mpg")
       function get_file_infor(url)
        dim fso,f
        set fso="createobject(""scrīpting.filesystemobject")
        set f="fso.getfile(url)"
        f.name:f.size:f.type:f.datacreated'///获取文件信息
        fso.deletefile(url)'/////删除文件
       end function
    --------获取文件夹里所有文件信息
    get_folder_infor("c:\kai")
    function get_folder_infor(folder)
    dim fso,f,f1,n
    set fso="createobject(""scrīpting,filesystemobject")
    set f="fso.getfolder(folder) set fc="f.files for each f1 in fc
    select case f1.name
    case"kai.mpg","she.mpg","dd.mp3"'//检查文件夹里是否含有这些文件
    end select
    next
    end function

     

    13   等待某个对象出现方法
    y="......waitproperty(""visible",true,10000)

     

    14   防程序中断方法
    On error resume next
    On error goto handle

     

    15  数组的应用:
    name="array(1,2,""aa","bb")
    name(2)="aa"

     

    16  正则表达式应用模板
    进行日期YYYY-MM-DD的格式检查 :
    Function RegExpTest(patrn, strng)
      Dim regEx, Match, Matches      ' Create variable.
      Set regEx = New RegExp         ' Create a regular expression.
      regEx.Pattern = patrn         ' Set pattern.
      regEx.IgnoreCase = True         ' Set case insensitivity.
      regEx.Global = True         ' Set global applicability.
      Set Matches = regEx.Execute(strng)   ' Execute search.
      For Each Match in Matches      ' Iterate Matches collection.
        RetStr = RetStr & "Match found at position "
        RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
        RetStr = RetStr & Match.Value & "'." & vbCRLF
      Next
      RegExpTest = RetStr
    End Function
    date_pattern="^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((01,3-9])|(1[0-2]))-(29|30)))))$"
    result_message=RegExpTest(date_pattern, inputbox("请你输入要检查的时间:"))'用其它正则表达式更改此处
    Select case result_message
    Case ""
             msgbox("你输入的日期格式与标准不匹配")
    case else  MsgBox(result_message)
    end select

     

    17   返回一个字符串在另一字符串中的位置
    instr(string1,string2)

     

    18   有时回放出现找不到对象时,可能不是由于你的代码问题,而是由于你的操作系统等设置问题;
    举例说明1:
    比如:你录制一个选择磁盘中的文件动作
    会录制为:
    .winlistview("  ").drap 46,99
    .winlistview("  ").draponitem "she.mp3"
    下次录制的时候,如果你的系统文件改为不显示扩展名,下次执行的时候,QTP就找不到she.mp3,只能找到she;
    举例说明2:
    有时由于不同操作系统以及不同的ie,导致有些窗口不能识别,比如在2000下弹出的网页对话框的标题是:
    “web对话框",而在2003上是”网页对话框"

     

    19  "is+*"类型function
    isarray'是否是数组
    isconnected'判断QTP是否连接到TD
    isdate'是否是合法的日期类型
    isempty'判断是否初始化
    isNull'判断是否为空值
    isNumeric'判断是否是数字型
    isobject'判断是否一个功能对象
    isready'判断设备是否准备就绪
    isRootFolder'是否是根目录

     

    20 Action之间的参数传递
    例如:在Action1中,有如下代码:
    out_str="This is out_string"
    RunAction "Action2",oneIteration,out_str
    在Acton2中,在其step->Action Properties中的,input参数栏,加入out_str后,
    msgbox(parameter("out_str")),就能正确显示参数了 

     

    21 Wscrīpt.Shell的一些应用
    set WshShell ="CreateObject(""Wscrīpt.Shell")
    WshShell.SendKeys "{ENTER}"     '模拟键盘进行操作
    WshShell.AppActivate "Calculator"             '启动应用程序

     

    22 获取对象属性名称用法:
    GetRoProperty----从应用程序界面上获取对象属性(即,是脚本运行时,获取的对象动态属性值)例如:获取对象库中index属性值,似乎只能用GetToProperty,因为应用程序界面上对象没有该属性,只是QTP为识别该对象创立的描述属性;
    GetToproperty----从对象库中描述对象的属性,静态值
    GetToProperties----获取用于标识对象的属性集;对于这个集合,有count等属性方法

     

    23 FireEvent的使用可以对一个对象进行更复杂的操作
    如:FireEvent("onfocus")   '使一个控件获取焦点
         FireEvent("ondblclick")  '实现双击/也可以在事件设定中针对该对象事件响应  

     

    24 模板的应用
    -----新建一个文本,输入一些新建Action时常包含的信息,然后保存为ActionTemplate.MST文件,
     并复制到QTP/dat目录下;这样每次新建action都会包含固定的信息了;
    例如:
    '-------------------脚本说明---------------
    '产品版本:      __Build(  )
    '测试员:
    '编写日期:
    '测试功能:
    '脚本类型:
    '被测试对象初始状态:
    '进展程度:
    '基本思路:
    '主要功能函数:
    '历史修改:
    '没解决的问题:
    '--------------------脚本内容-------------

     

    25 在对象库中,两个对象有时不能通过更改属性或命名来达到两个对象完全一致的替换;
    在web-mod项目中,我在对象库里添加了一个自动含有index标识属性的对象,然后每次通过SetToproperty来改变
    index值,对对象进行数据驱动,使其操作另一个对象,但脚本始终操作原先index属性值的对象;后来,把该对象
    删除掉,重新添加一个不自动含有index标识属性的该类对象,然后,手工添加,index标识属性,后来脚本能正常工作了,可见两次的对象属性完全一致,但形成方式不一样,导致的结果往往也不一样;

     

    26 childobject的应用
    childobject可以返回界面上满足条件的对象集合,而且与对象库里是否有这些对象无关,这就可以简化对象库;
    返回的对象集合的count方法可以返回对象个数,这就可以通过下标对单个对象进行操作;在出现index标识对象时
    可以进行运用
    如:Set m_WinCheck="Descrīption.Create()       m_WinCheck("nativeclass").Value="Button"
          set All_WinCheck="Window(""").Dialog("").Childobject(m_WinCheck)
          n="All_WinCheck.Count()      for i="0" to n-1
          All_WinCheck(i).Set "ON"
         next

    --以上是一些简单基础内容及我的经验心得,欢迎大家贴一些特色代码或具体应用的核心代码,谢谢

  • Selenium备忘

    2007-11-12 15:56:32

    作者 johnsonchen 目标文章 项目日志 - 2006-09-13


        最近的项目准备用Selenium作一部分的Regression Test。在SpringSide里参考了一下,又下了个Selenium IDE玩玩,觉得还蛮容易上手,基本上不需要手动写测试代码。
        但实操起来时面对各种复杂的页面情况遇到不少麻烦。感觉Selenium 的offical documentation写的比较high level, 最后找了个though works的ppt,算得上比较全面易懂。匆匆翻译了一下,供后来者参考。


    一、 格式
    1. Test Case 格式

       Title  
     命令(Command)   目标(Target)   值(Value)
     命令(Command)  目标(Target)    (&nbsp;)
     判断(Assertion)   期望值(Expected)   实际值(Actual)


    2. Test Suites 格式

     Title
     TestCase1.html
     TestCase2.html
     TestCase3.html

    二、 Commands (命令)

    • Action
      对当前状态进行操作
      失败时,停止测试
    • Assertion
      校验是否有产生正确的值
    • Element Locators
      指定HTML中的某元素
    • Patterns
      用于模式匹配

    1. Element Locators (元素定位器)

    • id=id
      id locator 指定HTML中的唯一id的元素 
    •  name=name
      name locator指定 HTML中相同name的元素中的第一个元素
    •  identifier=id
      identifier locator 首先查找HTML是否存在该id的元素, 若不存在,查找第一个该name的元素 
    • dom=javascrīptExpression
      dom locator用Javascrīpt表达式来定位HTML中的元素,注意必须要以”document”开头
      例如:
      dom=document.forms[‘myForm’].myDropdown
      dom=document.images[56]
    •  xpath=xpathExpression
      xpath locator用 XPath 表达式来定位HTML中的元素,必须注意要以”//”开头
      例如:
      xpath=//img[@alt=’The image alt text’]
      xpath=//table[@id=’table1’]//tr[4]/td[2]
    •  link=textPattern
      link locator 用link来选择HTML中的连接或锚元素
      例如:
      link=The link text
    • 在没有locator前序的情况下 Without a locator prefix, Selenium uses:
      如果以”document.”开头,则默认是使用 dom locator,如果是以“//”开头,则默认使用xpath locator,其余情况均认作identifier locator

    2. String Matching Patterns (字符串匹配模式)

    • glob:patthern
      glob模式,用通配符”*”代表任意长度字符,“?”代表一个字符
    • regexp:regexp
      正则表达式模式,用Javascrīpt正则表达式的形式匹配字符串
    • exact:string
      精确匹配模式,精确匹配整个字符串,不能用通配符
    • 在没有指定字符串匹配前序的时候,selenium 默认使用golb 匹配模式

    3. Select Option Specifiers (Select选项指定器)

    • label=labelPattern
      通过匹配选项中的文本指定选项
      例如:label=regexp:^[Oo]ther
    • value=valuePattern
      通过匹配选项中的值指定选项
      例如:value=other
    • id=id
      通过匹配选项的id指定选项
      例如: id=option1
    • index=index
      通过匹配选项的序号指定选项,序号从0开始
      例如:index=2
    • 在没有选项选择前序的情况下,默认是匹配选项的文本

    三、 Actions
    描述了用户所会作出的操作。
    Action 有两种形式: action和actionAndWait, action会立即执行,而actionAndWait会假设需要较长时间才能得到该action的相响,而作出等待,open则是会自动处理等待时间。

    • click
      click(elementLocator)
      - 点击连接,按钮,复选和单选框
      - 如果点击后需要等待响应,则用”clickAndWait”
      - 如果是需要经过Javascrīpt的alert或confirm对话框后才能继续操作,则需要调用verify或assert来告诉Selenium你期望对对话框进行什么操作。
       click  aCheckbox  
       clickAndWait  submitButton  
       clickAndWait   anyLink  

    • open
      open(url)

      - 在浏览器中打开URL,可以接受相对和绝对路径两种形式
      - 注意:该URL必须在与浏览器相同的安全限定范围之内
       open   /mypage  
       open  http://localhost/   

    • type
       type(inputLocator, value)
      - 模拟人手的输入过程,往指定的input中输入值
      - 也适合给复选和单选框赋值
      - 在这个例子中,则只是给钩选了的复选框赋值,注意,而不是改写其文本
       type  nameField   John Smith
       typeAndWait   textBoxThatSubmitsOnChange  newValue

    • select
      select(dropDownLocator, optionSpecifier)
      - 根据optionSpecifier选项选择器来选择一个下拉菜单选项
      - 如果有多于一个选择器的时候,如在用通配符模式,如”f*b*”,或者超过一个选项有相同的文本或值,则会选择第一个匹配到的值
       select    dropDown   Australian Dollars
       select    dropDown   index=0
       selectAndWait   currencySelector   value=AUD
       selectAndWait   currencySelector   label=Auslian D*rs

    •  goBack,close
      goBack()
      模拟点击浏览器的后退按钮
      close()
      模拟点击浏览器关闭按钮
    • selectWindow
      select(windowId)
      - 选择一个弹出窗口
      - 当选中那个窗口的时候,所有的命令将会转移到那窗口中执行
       selectWindow   myPopupWindow  
       selectWindow  null  

    • pause
      pause(millisenconds)
      - 根据指定时间暂停Selenium脚本执行
      - 常用在调试脚本或等待服务器段响应时
       pause   5000  
       pause   2000  

    • fireEvent
       fireEvent(elementLocatore,evenName)
      模拟页面元素事件被激活的处理动作
       fireEvent   textField focus 
       fireEvent  dropDown  blur

    • waitForCondition
      waitForCondition(JavascrīptSnippet,time)

      - 在限定时间内,等待一段Javascrīpt代码返回true值,超时则停止等待
       waitForCondition   var value=selenium.getText("foo"); value.match(/bar/);  3000

    • waitForValue
      waitForValue(inputLocator, value)
      - 等待某input(如hidden input)被赋予某值,
      - 会轮流检测该值,所以要注意如果该值长时间一直不赋予该input该值的话,可能会导致阻塞
       waitForValue  finishIndication isfinished 
           

    • store,stroreValue
      store(valueToStore, variablename)
      保存一个值到变量里。
      该值可以由自其他变量组合而成或通过Javascrīpt表达式赋值给变量
       store   Mr John Smith  fullname
       store   ${title} ${firstname} ${suname}  fullname
       store   javascrīpt{Math.round(Math.PI*100)/100}  PI
       storeValue  inputLocator  variableName

      把指定的input中的值保存到变量中
       storeValue   userName  userID 
       type   userName   ${userID}

    • storeText, storeAttribute
      storeText(elementLocator, variablename)
      把指定元素的文本值赋予给变量
       storeText   currentDate   expectedStartDate
       verifyValue   startDate   ${expectedStartDate}

      storeAttribute(elementLocator@attributeName,variableName)
      把指定元素的属性的值赋予给变量
       storeAttribute  input1@class    classOfInput1
       verifyAttribute   input2@class   ${classOfInput1}

    • chooseCancel.., answer..
      chooseCancelOnNextConfirmation()
      - 当下次Javascrīpt弹出confirm对话框的时候,让selenium选择Cancel
      - 如果没有该命令时,遇到confirm对话框Selenium默认返回true,如手动选择OK按钮一样
       chooseCancelOnNextConfirmation      

      - 如果已经运行过该命令,当下一次又有confirm对话框出现时,也会同样地再次选择Cancel
      answerOnNextPrompt(answerString)
      - 在下次Javascrīpt弹出prompt提示框时,赋予其anweerString的值,并选择确定
       answerOnNextPrompt   Kangaroo   

    四、 Assertions
    允许用户去检查当前状态。两种模式: Assert 和 Verify, 当Assert失败,则退出测试;当Verify失败,测试会继续运行。

    • assertLocation, assertTitle
      assertLocation(relativeLocation)
      判断当前是在正确的页面
       verifyLocation   /mypage  
       assertLocation   /mypage  

    • assertTitle(titlePattern)
      检查当前页面的title是否正确
       verifyTitle   My Page   
       assertTitle   My Page   

    • assertValue
      assertValue(inputLocator, valuePattern)
      - 检查input的值
      - 对于 checkbox或radio,如果已选择,则值为”on”,反之为”off”
       verifyValue   nameField   John Smith
       assertValue   document.forms[2].nameField  John Smith

    • assertSelected, assertSelectedOptions
      assertSelected(selectLocator, optionSpecifier)
      检查select的下拉菜单中选中的选型是否和optionSpecifer(Select选择选项器)的选项相同
       verifySelected   dropdown2   John Smith
       verifySelected   dorpdown2   value=js*123
       assertSelected   document.forms[2].dropDown  label=J*Smith
       assertSelected   document.forms[2].dropDown   index=0

    • assertSelectOptions(selectLocator, optionLabelList)
      - 检查下拉菜单中的选项的文本是否和optionLabelList相同
      - optionLabelList是以逗号分割的一个字符串
       verifySelectOptions   dropdown2   John Smith,Dave Bird
       assertSelectOptions   document.forms[2].dropdown  Smith,J,Bird,D

    • assertText
      assertText(elementLocator,textPattern)
      - 检查指定元素的文本
      - 只对有包含文本的元素生效
      - 对于Mozilla类型的浏览器,用textContent取元素的文本,对于IE类型的浏览器,用innerText取元素文本
       verifyText   statusMessage   Successful
       assertText   //div[@id='foo']//h1  Successful

       
    • assertTextPresent, assertAttribute
      assertTextPresent(text)
      检查在当前给用户显示的页面上是否有出现指定的文本
       verifyTextPresent   You are now logged in   
       assertTextPresent   You are now logged in   

    • assertAttribute(elementLocator@attributeName, ValuePattern)
      检查当前指定元素的属性的值
       verifyAttribute  txt1@class  bigAndBlod
       assertAttribute   document.images[0]@alt  alt-text
       verifyAttribute   //img[@id='foo']/alt   alt-text

    • assertTextPresent, etc.
      assertTextPresent(text)
      assertTextNotPresent(text)
      assertElementPresent(elementLocator)
       verifyElementPresent   submitButton   
       assertElementPresent   //img[@alt='foo']   
      assertElementNotPresent(elementLocator)
    • assertTable
      assertTable(cellAddress, valuePattern)
      - 检查table里的某个cell中的值
      - cellAddress的语法是tableName.row.column, 注意行列序号都是从0开始
       verifyTable   myTable.1.6  Submitted
       assertTable   results0.2   13

       
    • assertVisible, nonVisible
      assertVisible(elementLocator)
      - 检查指定的元素是否可视的
      - 隐藏一个元素可以用设置css的‘visibility’属性为’hidden’,也可以设置‘display’属性为‘none’
       verfyVisible   postcode   
       assertVisible   postcode   

    • assertNotVisible(elementLocator)
       verfyNotVisible   postcode   
       assertNotVisible   postcode   

    • Editable, non-editable
      assertEditable(inputLocator)
      检查指定的input是否可以编辑
       verifyEditable   shape   
       assertEditable   colour   

    • assertNotEditable(inputLocator)
      检查指定的input是否不可以编辑
    • assertAlert
      assertAlert(messagePattern)
      - 检查Javascrīpt是否有产生带指定message的alert对话框
      - alert产生的顺序必须与检查的顺序一致
      - 检查alert时会产生与手动点击’OK’按钮一样的效果。如果一个alert产生了,而你却没有去检查它,selenium会在下个action中报错。
      - 注意:Selenium 不支持 Javascrīpt 在onload()事件时 调用alert();在这种情况下,Selenium需要你自己手动来点击OK.
    • assertConfirmation
      assertConfirmation(messagePattern)
      - 检查Javascrīpt是否有产生带指定message的confirmation对话框和alert情况一样,confirmation对话框也必须在它们产生的时候进行检查
      - 默认情况下,Selenium会让confirm() 返回true, 相当于手动点击Ok按钮的效果。你能够通过chooseCancelOnNextConfirmation命令让confirm()返回false.同样地,如果一个cofirmation对话框出现了,但你却没有检查的话,Selenium将会在下个action中报错
      - 注意:在Selenium的环境下,confirmation对话框框将不会再出现弹出显式对话框
      - 注意:Selenium不支持在onload()事件时调用confirmation对话框,在这种情况下,会出现显示confirmatioin对话框,并需要你自己手动点击。
    •  assertPrompt
      assertPrompt(messagePattern)
      - 检查Javascrīpt是否有产生带指定message的Prompt对话框
      - 你检查的prompt的顺序Prompt对话框产生的顺序必须相同
      - 必须在verifyPrompt之前调用answerOnNextPrompt命令
      - 如果prompt对话框出现了但你却没有检查,则Selenium会在下个action中报错
       answerOnNextPrompt   Joe   
       click   id=delegate   
       verifyPrompt   Delegate to who?   


    五、 Parameters and Variables
    参数和变量的声明范围由简单的赋值到Javascrīpt表达式赋值。
    Store,storeValue 和storeText 为下次访问保存值。
    在Selenium内部是用一个叫storeVars的map来保存变量名。

    • Variable Substitution 变量替换
      提供了一个简单的方法去访问变量,语法 ${xxx}
       store    Mr   title
       storeValue   nameField   surname
       store    ${title} ${suname}  fullname
       type   textElement   Full name is: ${fullname}

    •  Javascrīpt Evaluation Javascrīpt赋值
      你能用Javascrīpt来构建任何你所需要的值。
      这个参数是以javascrīpt开头,语法是 javascrīpt{‘with a trailing’}。
      可以通过Javascrīpt表达式给某元素赋值。
      store   javascrīpt{'merchant'+(new Date()).getTime()}   merchantId
       type  textElement   javascrīpt{storedVars['merchantId'].toUpperCase()}

    • Generating Unique values 产生唯一值.  
      问题:你需要唯一的用户名
      解决办法: 基于时间来产生用户名,如’fred’+(new Date().getTime())
  • Selenium Reference

    2007-11-12 14:06:18

    Concepts

    A command is what tells Selenium what to do. Selenium commands come in three 'flavors': Actions, Accessors and Assertions. Each command call is one line in the test table of the form:

    command target value

    Actions are commands that generally manipulate the state of the application. They do things like "click this link" and "select that option". If an Action fails, or has an error, the execution of the current test is stopped.

    Many Actions can be called with the "AndWait" suffix, e.g. "clickAndWait". This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.

    Accessors examine the state of the application and store the results in variables, e.g. "storeTitle". They are also used to automatically generate Assertions.

    Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include "make sure the page title is X" and "verify that this checkbox is checked".

    All Selenium Assertions can be used in 3 modes: "assert", "verify", and "waitFor". For example, you can "assertText", "verifyText" and "waitForText". When an "assert" fails, the test is aborted. When a "verify" fails, the test will continue execution, logging the failure. This allows a single "assert" to ensure that the application is on the correct page, followed by a bunch of "verify" assertions to test form field values, labels, etc.

    "waitFor" commands wait for some condition to become true (which can be useful for testing Ajax applications). They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting (see the setTimeout action below).

    Element Locators tell Selenium which HTML element a command refers to. Many commands require an Element Locator as the "target" attribute. Examples of Element Locators include "elementId" and "document.forms[0].element". These are described more clearly in the next section.

    Patterns are used for various reasons, e.g. to specify the expected value of an input field, or identify a select option. Selenium supports various types of pattern, including regular-expressions, all of which are described in more detail below.

    Defines an object that runs Selenium commands.

    Element Locators

    Element Locators tell Selenium which HTML element a command refers to. The format of a locator is:

    locatorType=argument

    We support the following strategies for locating elements:

    identifier=id
    Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.)
    id=id
    Select the element with the specified @id attribute.
    name=name
    Select the first element with the specified @name attribute.
    • username
    • name=username
    The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
    • name=flavour value=chocolate
    dom=javascrīptExpression
    Find an element using Javascrīpt traversal of the HTML Document Object Model. DOM locators must begin with "document.".
    • dom=document.forms['myForm'].myDropdown
    • dom=document.images[56]
    xpath=xpathExpression
    Locate an element using an XPath expression.
    • xpath=//img[@alt='The image alt text']
    • xpath=//table[@id='table1']//tr[4]/td[2]
    link=textPattern
    Select the link (anchor) element which contains text matching the specified pattern.
    • link=The link text
    css=cssSelectorSyntax
    Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
    • css=a[href="#id3"]
    • css=span#firstChild + span
    Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

    Without an explicit locator prefix, Selenium uses the following default strategies:

    • dom, for locators starting with "document."
    • xpath, for locators starting with "//"
    • identifier, otherwise

    Element Filters

    Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.

    Filters look much like locators, ie.

    filterType=argument

    Supported element-filters are:

    value=valuePattern

    Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.

    index=index

    Selects a single element based on its position in the list (offset from zero).

    String-match Patterns

    Various Pattern syntaxes are available for matching string values:

    glob:pattern
    Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents any sequence of characters, and "?" represents any single character. Glob patterns match against the entire string.
    regexp:regexp
    Match a string using a regular-expression. The full power of Javascrīpt regular-expressions is available.
    exact:string
    Match a string exactly, verbatim, without any of that fancy wildcard stuff.

    If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.

    Selenium Actions

    addSelection ( locator,optionLocator )
    Add a selection to the set of selected options in a multi-select element using an option locator. @see #doSelect for details of option locators

    Arguments:

    • locator - an element locator identifying a multi-select box
    • optionLocator - an option locator (a label by default)

    answerOnNextPrompt ( answer )
    Instructs Selenium to return the specified answer string in response to the next Javascrīpt prompt [window.prompt()].

    Arguments:

    • answer - the answer to give in response to the prompt pop-up

    check ( locator )
    Check a toggle-button (checkbox/radio)

    Arguments:


    chooseCancelOnNextConfirmation ( )
    By default, Selenium's overridden window.confirm() function will return true, as if the user had manually clicked OK. After running this command, the next call to confirm() will return false, as if the user had clicked Cancel.
    click ( locator )
    Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad.

    Arguments:

    • locator - an element locator

    clickAt ( locator,coordString )
    Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad. Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • locator - an element locator
    • coordString - specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.

    close ( )
    Simulates the user clicking the "close" button in the titlebar of a popup window or tab.
    createCookie ( nameValuePair,optionsString )
    Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.

    Arguments:

    • nameValuePair - name and value of the cookie in a format "name=value"
    • optionsString - options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.

    deleteCookie ( name,path )
    Delete a named cookie with specified path.

    Arguments:

    • name - the name of the cookie to be deleted
    • path - the path property of the cookie to be deleted

    dragdrop ( locator,movementsString )
    Drags an element a certain distance and then drops it Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • locator - an element locator
    • movementsString - offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"

    fireEvent ( locator,eventName )
    Explicitly simulate an event, to trigger the corresponding "onevent" handler.

    Arguments:

    • locator - an element locator
    • eventName - the event name, e.g. "focus" or "blur"

    goBack ( )
    Simulates the user clicking the "back" button on their browser.
    keyDown ( locator,keySequence )
    Simulates a user pressing a key (without releasing it yet).

    Arguments:

    • locator - an element locator
    • keySequence - Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".

    keyPress ( locator,keySequence )
    Simulates a user pressing and releasing a key.

    Arguments:

    • locator - an element locator
    • keySequence - Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".

    keyUp ( locator,keySequence )
    Simulates a user releasing a key.

    Arguments:

    • locator - an element locator
    • keySequence - Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".

    mouseDown ( locator )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

    Arguments:


    mouseDownAt ( locator,coordString )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element. Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • locator - an element locator
    • coordString - specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.

    mouseMove ( locator )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

    Arguments:


    mouseMoveAt ( locator,coordString )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element. Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • locator - an element locator
    • coordString - specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.

    mouseOut ( locator )
    Simulates a user moving the mouse pointer away from the specified element.

    Arguments:


    mouseOver ( locator )
    Simulates a user hovering a mouse over the specified element.

    Arguments:


    mouseUp ( locator )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element.

    Arguments:


    mouseUpAt ( locator,coordString )
    Simulates a user pressing the mouse button (without releasing it yet) on the specified element. Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • locator - an element locator
    • coordString - specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.

    open ( url )
    Opens an URL in the test frame. This accepts both relative and absolute URLs. The "open" command waits for the page to load before proceeding, ie. the "AndWait" suffix is implicit. Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy). If you need to open an URL on another domain, use the Selenium Server to start a new browser session on that domain.

    Arguments:

    • url - the URL to open; may be relative or absolute

    refresh ( )
    Simulates the user clicking the "Refresh" button on their browser.
    removeSelection ( locator,optionLocator )
    Remove a selection from the set of selected options in a multi-select element using an option locator. @see #doSelect for details of option locators

    Arguments:

    • locator - an element locator identifying a multi-select box
    • optionLocator - an option locator (a label by default)

    select ( selectLocator,optionLocator )
    Select an option from a drop-down using an option locator.

    Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.

    label=labelPattern
    matches options based on their labels, i.e. the visible text. (This is the default.)
    • label=regexp:^[Oo]ther
    value=valuePattern
    matches options based on their values.
    • value=other
    id=id
    matches options based on their ids.
    • id=option1
    index=index
    matches an option based on its index (offset from zero).
    • index=2

    If no option locator prefix is provided, the default behaviour is to match on label.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • optionLocator - an option locator (a label by default)

    selectFrame ( locator )
    Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top".

    You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames["subframe"]

    Arguments:


    selectWindow ( windowID )
    Selects a popup window; once a popup window has been selected, all commands go to that window. To select the main window again, use "null" as the target.

    Arguments:

    • windowID - the Javascrīpt window ID of the window to select

    setContext ( context,logLevelThreshold )
    Writes a message to the status bar and adds a note to the browser-side log.

    If logLevelThreshold is specified, set the threshold for logging to that level (debug, info, warn, error).

    (Note that the browser-side logs will not be sent back to the server, and are invisible to the Client Driver.)

    Arguments:

    • context - the message to be sent to the browser
    • logLevelThreshold - one of "debug", "info", "warn", "error", sets the threshold for browser-side logging

    setCursorPosition ( locator,position )
    Moves the text cursor to the specified position in the given input element or textarea. This method will fail if the specified element isn't an input element or textarea.

    Arguments:

    • locator - an element locator pointing to an input element or textarea
    • position - the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.

    setTimeout ( timeout )
    Specifies the amount of time that Selenium will wait for actions to complete.

    Actions that require waiting include "open" and the "waitFor*" actions.

    The default timeout is 30 seconds.

    Arguments:

    • timeout - a timeout in milliseconds, after which the action will return with an error

    submit ( formLocator )
    Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms.

    Arguments:


    type ( locator,value )
    Sets the value of an input field, as though you typed it in.

    Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.

    Arguments:


    uncheck ( locator )
    Uncheck a toggle-button (checkbox/radio)

    Arguments:


    waitForCondition ( scrīpt,timeout )
    Runs the specified Javascrīpt snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered.

    Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the Javascrīpt snippet selenium.browserbot.getCurrentWindow(), and then run your Javascrīpt in there

    Arguments:

    • scrīpt - the Javascrīpt snippet to run
    • timeout - a timeout in milliseconds, after which this command will return with an error

    waitForPageToLoad ( timeout )
    Waits for a new page to load.

    You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc. (which are only available in the JS API).

    Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded" flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load.

    Arguments:

    • timeout - a timeout in milliseconds, after which this command will return with an error

    waitForPopUp ( windowID,timeout )
    Waits for a popup window to appear and load up.

    Arguments:

    • windowID - the Javascrīpt window ID of the window that will appear
    • timeout - a timeout in milliseconds, after which the action will return with an error

    windowFocus ( windowName )
    Gives focus to a window

    Arguments:

    • windowName - name of the window to be given focus

    windowMaximize ( windowName )
    Resize window to take up the entire screen

    Arguments:

    • windowName - name of the window to be enlarged

    Selenium Accessors

    storeAlert ( variableName )
    Retrieves the message of a Javascrīpt alert generated during the previous action, or fail if there were no alerts.

    Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not get/verify it, the next Selenium action will fail.

    NOTE: under Selenium, Javascrīpt alerts will NOT pop up a visible alert dialog.

    NOTE: Selenium does NOT support Javascrīpt alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.

    Returns:
    The message of the most recent Javascrīpt alert

    Related Assertions, automatically generated:


    storeAllButtons ( variableName )
    Returns the IDs of all buttons on the page.

    If a given button has no ID, it will appear as "" in this array.

    Returns:
    the IDs of all buttons on the page

    Related Assertions, automatically generated:


    storeAllFields ( variableName )
    Returns the IDs of all input fields on the page.

    If a given field has no ID, it will appear as "" in this array.

    Returns:
    the IDs of all field on the page

    Related Assertions, automatically generated:


    storeAllLinks ( variableName )
    Returns the IDs of all links on the page.

    If a given link has no ID, it will appear as "" in this array.

    Returns:
    the IDs of all links on the page

    Related Assertions, automatically generated:


    storeAllWindowIds ( variableName )
    Returns the IDs of all windows that the browser knows about.

    Returns:
    the IDs of all windows that the browser knows about.

    Related Assertions, automatically generated:


    storeAllWindowNames ( variableName )
    Returns the names of all windows that the browser knows about.

    Returns:
    the names of all windows that the browser knows about.

    Related Assertions, automatically generated:

    • assertAllWindowNames ( pattern )
    • assertNotAllWindowNames ( pattern )
    • verifyAllWindowNames ( pattern )
    • verifyNotAllWindowNames ( pattern )
    • waitForAllWindowNames ( pattern )
    • waitForNotAllWindowNames ( pattern )

    storeAllWindowTitles ( variableName )
    Returns the titles of all windows that the browser knows about.

    Returns:
    the titles of all windows that the browser knows about.

    Related Assertions, automatically generated:

    • assertAllWindowTitles ( pattern )
    • assertNotAllWindowTitles ( pattern )
    • verifyAllWindowTitles ( pattern )
    • verifyNotAllWindowTitles ( pattern )
    • waitForAllWindowTitles ( pattern )
    • waitForNotAllWindowTitles ( pattern )

    storeAttribute ( attributeLocator, variableName )
    Gets the value of an element attribute. Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to get null event arguments. Read the bug for more details, including a workaround.

    Arguments:

    • attributeLocator - an element locator followed by an
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the value of the specified attribute

    Related Assertions, automatically generated:

    • assertAttribute ( attributeLocator, pattern )
    • assertNotAttribute ( attributeLocator, pattern )
    • verifyAttribute ( attributeLocator, pattern )
    • verifyNotAttribute ( attributeLocator, pattern )
    • waitForAttribute ( attributeLocator, pattern )
    • waitForNotAttribute ( attributeLocator, pattern )

    storeAttributeFromAllWindows ( attributeName, variableName )
    Returns every instance of some attribute from all known windows.

    Arguments:

    • attributeName - name of an attribute on the windows
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the set of values of this attribute from all known windows.

    Related Assertions, automatically generated:

    • assertAttributeFromAllWindows ( attributeName, pattern )
    • assertNotAttributeFromAllWindows ( attributeName, pattern )
    • verifyAttributeFromAllWindows ( attributeName, pattern )
    • verifyNotAttributeFromAllWindows ( attributeName, pattern )
    • waitForAttributeFromAllWindows ( attributeName, pattern )
    • waitForNotAttributeFromAllWindows ( attributeName, pattern )

    storeBodyText ( variableName )
    Gets the entire text of the page.

    Returns:
    the entire text of the page

    Related Assertions, automatically generated:


    storeConfirmation ( variableName )
    Retrieves the message of a Javascrīpt confirmation dialog generated during the previous action.

    By default, the confirm function will return true, having the same effect as manually clicking OK. This can be changed by prior execution of the chooseCancelOnNextConfirmation command. If an confirmation is generated but you do not get/verify it, the next Selenium action will fail.

    NOTE: under Selenium, Javascrīpt confirmations will NOT pop up a visible dialog.

    NOTE: Selenium does NOT support Javascrīpt confirmations that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until you manually click OK.

    Returns:
    the message of the most recent Javascrīpt confirmation dialog

    Related Assertions, automatically generated:


    storeCookie ( variableName )
    Return all cookies of the current page under test.

    Returns:
    all cookies of the current page under test

    Related Assertions, automatically generated:


    storeCursorPosition ( locator, variableName )
    Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.

    Specifically, if the cursor/selection has been cleared by Javascrīpt, this command will tend to return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243.

    This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.

    Arguments:

    • locator - an element locator pointing to an input element or textarea
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the numerical position of the cursor in the field

    Related Assertions, automatically generated:

    • assertCursorPosition ( locator, pattern )
    • assertNotCursorPosition ( locator, pattern )
    • verifyCursorPosition ( locator, pattern )
    • verifyNotCursorPosition ( locator, pattern )
    • waitForCursorPosition ( locator, pattern )
    • waitForNotCursorPosition ( locator, pattern )

    storeElementHeight ( locator, variableName )
    Retrieves the height of an element

    Arguments:

    • locator - an element locator pointing to an element
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    height of an element in pixels

    Related Assertions, automatically generated:

    • assertElementHeight ( locator, pattern )
    • assertNotElementHeight ( locator, pattern )
    • verifyElementHeight ( locator, pattern )
    • verifyNotElementHeight ( locator, pattern )
    • waitForElementHeight ( locator, pattern )
    • waitForNotElementHeight ( locator, pattern )

    storeElementIndex ( locator, variableName )
    Get the relative index of an element to its parent (starting from 0). The comment node and empty text node will be ignored.

    Arguments:

    • locator - an element locator pointing to an element
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    of relative index of the element to its parent (starting from 0)

    Related Assertions, automatically generated:

    • assertElementIndex ( locator, pattern )
    • assertNotElementIndex ( locator, pattern )
    • verifyElementIndex ( locator, pattern )
    • verifyNotElementIndex ( locator, pattern )
    • waitForElementIndex ( locator, pattern )
    • waitForNotElementIndex ( locator, pattern )

    storeElementPositionLeft ( locator, variableName )
    Retrieves the horizontal position of an element

    Arguments:

    • locator - an element locator pointing to an element OR an element itself
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    of pixels from the edge of the frame.

    Related Assertions, automatically generated:

    • assertElementPositionLeft ( locator, pattern )
    • assertNotElementPositionLeft ( locator, pattern )
    • verifyElementPositionLeft ( locator, pattern )
    • verifyNotElementPositionLeft ( locator, pattern )
    • waitForElementPositionLeft ( locator, pattern )
    • waitForNotElementPositionLeft ( locator, pattern )

    storeElementPositionTop ( locator, variableName )
    Retrieves the vertical position of an element

    Arguments:

    • locator - an element locator pointing to an element OR an element itself
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    of pixels from the edge of the frame.

    Related Assertions, automatically generated:

    • assertElementPositionTop ( locator, pattern )
    • assertNotElementPositionTop ( locator, pattern )
    • verifyElementPositionTop ( locator, pattern )
    • verifyNotElementPositionTop ( locator, pattern )
    • waitForElementPositionTop ( locator, pattern )
    • waitForNotElementPositionTop ( locator, pattern )

    storeElementWidth ( locator, variableName )
    Retrieves the width of an element

    Arguments:

    • locator - an element locator pointing to an element
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    width of an element in pixels

    Related Assertions, automatically generated:

    • assertElementWidth ( locator, pattern )
    • assertNotElementWidth ( locator, pattern )
    • verifyElementWidth ( locator, pattern )
    • verifyNotElementWidth ( locator, pattern )
    • waitForElementWidth ( locator, pattern )
    • waitForNotElementWidth ( locator, pattern )

    storeEval ( scrīpt, variableName )
    Gets the result of evaluating the specified Javascrīpt snippet. The snippet may have multiple lines, but only the result of the last line will be returned.

    Note that, by default, the snippet will run in the context of the "selenium" object itself, so this will refer to the Selenium object, and window will refer to the top-level runner test window, not the window of your application.

    If you need a reference to the window of your application, you can refer to this.browserbot.getCurrentWindow() and if you need to use a locator to refer to a single element in your application page, you can use this.page().findElement("foo") where "foo" is your locator.

    Arguments:

    • scrīpt - the Javascrīpt snippet to run
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the results of evaluating the snippet

    Related Assertions, automatically generated:


    storeExpression ( expression, variableName )
    Returns the specified expression.

    This is useful because of Javascrīpt preprocessing. It is used to generate commands like assertExpression and waitForExpression.

    Arguments:

    • expression - the value to return
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the value passed in

    Related Assertions, automatically generated:

    • assertExpression ( expression, pattern )
    • assertNotExpression ( expression, pattern )
    • verifyExpression ( expression, pattern )
    • verifyNotExpression ( expression, pattern )
    • waitForExpression ( expression, pattern )
    • waitForNotExpression ( expression, pattern )

    storeHtmlSource ( variableName )
    Returns the entire HTML source between the opening and closing "html" tags.

    Returns:
    the entire HTML source

    Related Assertions, automatically generated:


    storeLocation ( variableName )
    Gets the absolute URL of the current page.

    Returns:
    the absolute URL of the current page

    Related Assertions, automatically generated:


    storeLogMessages ( variableName )
    Return the contents of the log.

    This is a placeholder intended to make the code generator make this API available to clients. The selenium server will intercept this call, however, and return its recordkeeping of log messages since the last call to this API. Thus this code in Javascrīpt will never be called.

    The reason I opted for a servercentric solution is to be able to support multiple frames served from different domains, which would break a centralized Javascrīpt logging mechanism under some conditions.

    Returns:
    all log messages seen since the last call to this API

    Related Assertions, automatically generated:


    storePrompt ( variableName )
    Retrieves the message of a Javascrīpt question prompt dialog generated during the previous action.

    Successful handling of the prompt requires prior execution of the answerOnNextPrompt command. If a prompt is generated but you do not get/verify it, the next Selenium action will fail.

    NOTE: under Selenium, Javascrīpt prompts will NOT pop up a visible dialog.

    NOTE: Selenium does NOT support Javascrīpt prompts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.

    Returns:
    the message of the most recent Javascrīpt question prompt

    Related Assertions, automatically generated:


    storeSelectedId ( selectLocator, variableName )
    Gets option element ID for selected option in the specified select element.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the selected option ID in the specified select drop-down

    Related Assertions, automatically generated:

    • assertSelectedId ( selectLocator, pattern )
    • assertNotSelectedId ( selectLocator, pattern )
    • verifySelectedId ( selectLocator, pattern )
    • verifyNotSelectedId ( selectLocator, pattern )
    • waitForSelectedId ( selectLocator, pattern )
    • waitForNotSelectedId ( selectLocator, pattern )

    storeSelectedIds ( selectLocator, variableName )
    Gets all option element IDs for selected options in the specified select or multi-select element.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    an array of all selected option IDs in the specified select drop-down

    Related Assertions, automatically generated:

    • assertSelectedIds ( selectLocator, pattern )
    • assertNotSelectedIds ( selectLocator, pattern )
    • verifySelectedIds ( selectLocator, pattern )
    • verifyNotSelectedIds ( selectLocator, pattern )
    • waitForSelectedIds ( selectLocator, pattern )
    • waitForNotSelectedIds ( selectLocator, pattern )

    storeSelectedIndex ( selectLocator, variableName )
    Gets option index (option number, starting at 0) for selected option in the specified select element.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    the selected option index in the specified select drop-down

    Related Assertions, automatically generated:

    • assertSelectedIndex ( selectLocator, pattern )
    • assertNotSelectedIndex ( selectLocator, pattern )
    • verifySelectedIndex ( selectLocator, pattern )
    • verifyNotSelectedIndex ( selectLocator, pattern )
    • waitForSelectedIndex ( selectLocator, pattern )
    • waitForNotSelectedIndex ( selectLocator, pattern )

    storeSelectedIndexes ( selectLocator, variableName )
    Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • variableName - the name of a variable in which the result is to be stored.

    Returns:
    an array of all selected option indexes in the specified select drop-down

    Related Assertions, automatically generated:

    • assertSelectedIndexes ( selectLocator, pattern )
    • assertNotSelectedIndexes ( selectLocator, pattern )
    • verifySelectedIndexes ( selectLocator, pattern )
    • verifyNotSelectedIndexes ( selectLocator, pattern )
    • waitForSelectedIndexes ( selectLocator, pattern )
    • waitForNotSelectedIndexes ( selectLocator, pattern )

    storeSelectedLabel ( selectLocator, variableName )
    Gets option label (visible text) for selected option in the specified select element.

    Arguments:

    • selectLocator - an element locator identifying a drop-down menu
    • variableName - the name of a variable in which the result is to be stored.

    Returns
Open Toolbar