Kev*_* Yu 2 selenium review-board codemirror robotframework
最近,我开始使用 Robot 和 Selenium2Library 来自动化一些 GUI 测试用例。我正在自动化的应用程序之一是 ReviewBoard。
到目前为止,我已经能够自动化一些东西,但在将文本输入文本区域时遇到很多问题。一个例子是评论板上的描述字段。
我最新的尝试是
:FOR ${URL} in @{URL_LIST}
\ Go To ${URL}
# Enter team reviewer name and press ok
\ Click Element xpath=//*[@id="fieldset_reviewers_body"]/tr[2]/td/a/div[@class="rb-icon rb-icon-edit"]
\ Input Text xpath=//*[@id="fieldset_reviewers_body"]/tr[2]/td/form/input rbtest_teamreviewer1
\ Press Key xpath=//*[@id="fieldset_reviewers_body"]/tr[2]/td/form/input \\9
\ Click Element xpath=//*[@id="fieldset_reviewers_body"]/tr[2]/td/form/span/input[@class="save"]
# Fill out Testing Done field
\ Click Element xpath=//*[@id="review_request_main"]/div[2]/label/a/div[@class="rb-icon rb-icon-edit"]
\ Press Key xpath=//*[@id='review_request_main']/div[2]/div/form/*//textarea Testing Done
\ Click Element xpath=//*[@id="review_request_main"]/div[2]/div/form/div[2]/input[@class="save"]
Run Code Online (Sandbox Code Playgroud)
但是,我收到了异常
ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的方法,例如使用输入文本而不是按键,但遇到类似的问题...输入类型时没有任何问题。
有谁知道我该如何解决这个问题?
如果您有兴趣,可以在http://demo.reviewboard.org/r/1502/查看演示评论板,用户名:guest6317 密码:demo
CodeMirror 用它自己的对象替换文本区域。该对象具有与小部件交互的方法。但是,在评论板的情况下,只有单击文本区域后,该对象才会初始化。所以,解决方案将如下所示:
第一步是单击文本区域以初始化小部件。这可以通过“Click Element”关键字轻松完成:
click element id=field_description
Run Code Online (Sandbox Code Playgroud)
评审板开发人员可能拥有该对象的引用,因此您可以向他们询问变量的名称。但是,我们可以创建自己的变量用于测试目的。CodeMirrorCodeMirror在包含编辑器的 div 上添加了一个属性,因此可以使用此信息来保存对临时 JavaScript 变量的引用:
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
Run Code Online (Sandbox Code Playgroud)
CodeMirror 编辑器有许多与编辑器内容交互的方法。例如,如果您想用自己的字符串替换内容,则可以调用该setValue方法。
例如,将所有数据替换为“Hello world!” 你可以这样做:
execute javascript _editor.setValue("Hello world!");
Run Code Online (Sandbox Code Playgroud)
这是一个完整的测试脚本,它将编辑器的内容替换为“Hello world”,然后暂停,以便您可以验证它是否有效。我在linux系统上用chrome和firefox测试了这个。
*** Variables ***
${ROOT} http://demo.reviewboard.org
${BROWSER} chrome
${USERNAME} guest6317
${PASSWORD} demo
*** Settings ***
Library Selenium2Library
Library Dialogs
Suite Setup open browser ${ROOT} ${BROWSER}
Suite Teardown close all browsers
*** Test Cases ***
Example
[Setup] run keywords
... Log in
... AND go to ${ROOT}/r/1502/
click element id=field_description
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
... _editor.setValue("Hello world!");
pause execution
*** Keywords ***
Log in
go to ${ROOT}/account/login
input text id=id_username ${USERNAME}
input text id=id_password ${PASSWORD}
submit form
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3142 次 |
| 最近记录: |