Robot Selenium-将文本输入代码镜像文本区域
最近,我开始使用Robot和Selenium2库来自动化一些GUI测试用例。我正在自动化的应用程序之一是ReviewBoard 到目前为止,我已经能够自动化一些东西,但在将文本输入到文本区域时有很多问题。例如,reviewboard上的description字段 我最近的尝试是Robot Selenium-将文本输入代码镜像文本区域,selenium,robotframework,codemirror,review-board,Selenium,Robotframework,Codemirror,Review Board,最近,我开始使用Robot和Selenium2库来自动化一些GUI测试用例。我正在自动化的应用程序之一是ReviewBoard 到目前为止,我已经能够自动化一些东西,但在将文本输入到文本区域时有很多问题。例如,reviewboard上的description字段 我最近的尝试是 :FOR ${URL} in @{URL_LIST} \ Go To ${URL} # Enter team reviewer name and press ok \ Click Element xpath
: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"]
然而,我收到了一个例外
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)
ElementNotVisibleException:消息:元素当前不可见,因此可能无法与之交互
堆栈跟踪:
在fxdriver.premissions.visible(file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command processor.js:10092)
在DelayedCommand.prototype.CheckPremissions\u(file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command processor.js:12644)
在DelayedCommand.prototype.executeInternal\uh处(file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command processor.js:12661)
在DelayedCommand.prototype.executeInternal\u(file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command processor.js:12666)
在DelayedCommand.prototype.execute/<(file:///tmp/tmpW24ACY/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command processor.js:12608)
我尝试过不同的方法,比如用输入文本代替按键,但也有类似的问题……当输入类型时,我没有任何问题
有人知道我怎样才能解决这个问题吗
如果您感兴趣,可以在上查看演示评论板,用户名:guest6317密码:democodemirr使用自己的对象替换文本区域。此对象具有与小部件交互的方法。但是,在reviewboard中,只有单击textarea,该对象才会初始化。因此,解决方案如下所示:
CodeMirror
属性,以便可以使用此信息保存对临时javascript变量的引用:
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
步骤3:与编辑器交互
CodeMirror编辑器具有与编辑器内容交互的功能。例如,如果要用自己的字符串替换内容,可以调用setValue
方法
例如,要用“Hello world!”替换所有数据,可以执行以下操作:
execute javascript _editor.setValue("Hello world!");
第四步:把所有的东西放在一起
下面是一个完整的测试脚本,它将编辑器的内容替换为“helloworld”,然后暂停,以便您可以验证它是否工作。我用chrome和firefox在linux系统上进行了测试
*** 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
您好@Kevin Yu-请提供您在此处编写的完整代码好吗?一旦单击
rb图标编辑
,页面将生成一个新的CodeMirror编辑器实例。此处介绍了更改其值的正确方法:。但是您需要知道CodeMirror对象的名称。我建议你向开发者询问这个问题。知道对象名称后,使用RobotFramework的executeJavaScript
运行javascript,而不是按键
。@好奇的是,我已经用完整的代码更新了它。谢谢。尽管如此,这些代码还是完整的。你用哪种语言写的代码?复制并粘贴上述问题中的代码。您可以使用代码中的测试数据更新敏感数据,但请提供您编写的清晰代码。将此标记为可接受的答案,因为它全面而准确。最终,在看到您的答案之前,我所做的是:执行Javascript文档.getElementsByCassName(“CodeMirror”)[0].CodeMirror.setValue(“hello world”);我尝试了一切我可以与输入文本功能,但它没有工作,无论我的目标。Javascript解决方案运行良好。谢谢
*** 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