Robot Selenium - Enter text into CodeMirror text area - selenium

Recently I've started using Robot with Selenium2Library to automate some GUI test cases. One of the application I'm automating is ReviewBoard.
So far I've been able to automate some stuff but having a lot of problem with inputting text into text area. An example would be the description field on reviewboard.
My latest attempt is
: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"]
However, I'm receving the exception
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)
I've try different ways such as using Input Text instead of Press Key but having similar problem...I don't have any problem when type is input.
Does anyone have any idea how I might be able to solve this?
If you are interested, you can view the demo reviewboard at http://demo.reviewboard.org/r/1502/ with username:guest6317 password:demo

CodeMirror replaces the textarea with its own object. This object has methods for interacting with the widget. However, in the case of reviewboard this object isn't initialized until you click on the textarea. So, the solution is going to look like this:
find and click on the textarea
find the reference to the CodeMirror editor object
use CodeMirror methods to interact with the editor widget
Step 1: clicking on the text area
The first step is to click on the textarea in order to initialize the widget. This can be done easily with the "Click Element" keyword:
click element id=field_description
Step 2: get a reference to the editor object
The reviewboard developers probably have a reference to the object, so you could ask them for the name of the variable. However, we can create our own variable for testing purposes. CodeMirror adds a CodeMirror attribute on the div that contains the editor so can use this information to save a reference to a temporary javascript variable:
Execute javascript
... _editor = document.querySelectorAll("div.CodeMirror")[0].CodeMirror;
Step 3: interacting with the editor
The CodeMirror editor has many methods for interacting with the contents of the editor. For example, if you want to replace the contents with your own string, you can call the setValue method.
For example, to replace all of the data with "Hello world!" you could do this:
execute javascript _editor.setValue("Hello world!");
Step 4: putting it all together
Here is a complete test script that replaces the contents of the editor with "Hello world", and then pauses so you can verify that it worked. I tested this on a linux system with chrome and 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

Related

Clicking a 'homepage' link in robot framework

I am writing test scripts using the Robot Framework & Selenium2Library for testing a web application.
The problem I have right now is that after the user has logged in, my script does not click the 'homepage' link to proceed to the Homepage, the application just disappears and command prompt gives me 'passed' results.
I want the script to click the link and then proceed to the Homepage,This is my code:
ClickHomePage
Click Link xpath=//*[#href="itinerary.php"]
I would appreciate your help. Thank you!
I have seen things like this generally when running tests on selenium. They could be really fast. I sometimes have to use breakpoints and debugging if I really want to see things happening during the test.
Unless you have another line of code after clicking the link, that is where the execution will end. Therefore, if you do want to see the homepage you may need to include a line a code that interacts with the homepage or simply a wait statement after clicking the link.
Try this code another way.
*** Variable ***
${profile} https://web.facebook.com/xxx
*** Keywords ***
Click Profile
[Arguments] ${xpath}
Click Element ${xpath}
*** Test Cases ***
Go To ${profile}
Hope to help.

Click LinkedIn share button using Robot framework selenium library

I am a newbie in using robot framework.I would like to click linkedin share button using selenium library. From my understanding linkedin share button is of type submit and value Share. can someone suggest how to use click element or click button for this. Thanks.
Here is a snippet to help you get started:
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Click share
Open Browser
... url=https://put-your-link-here
... browser=googlechrome
Click Button Share
Just put the right URL there, choose the browser you want to use, and check the name of the button. You can give this a go saving it to a file test.robot, for example, and run it with:
pybot test.robot
From there, the Documentation is your best friend.
I found an answer to my question. Before clicking an element should make sure that the element is visible. So below is the code
Wait Until Element is Visible css=input[value="Share"]
Click Element css=input[value="Share"]

Captcha with Selenium IDE - can I do a 'pause' and ask the 'user' to enter the CAPTCA

I am using Selenium IDE with my Firefox browser extension, it works pretty well but I have a registration form that uses an CAPTCHA - obviously it is impossible to get the Selenium to 'read' the CAPTCHA (that would make it somewhat useless if it did) - but I need to amend my test to alert the user that they should add the CAPTCA they see on the screen within x seconds.
I have no idea if this is possible - any advice appreciated.
Yes this is possible to alert user to enter the Captcha value. Please use below command in Selenium IDE.
Command: storeEval
Target: prompt("Enter Captcha Value")
Value: var
This prompts you to enter the Captcha value. You can see the Captcha and then enters it. This prompted value is stored in var. I then use as entering in Captcha field.
Command: type
Target: your captcha location
Value: ${var}
There is also another way where you can skip this section if there is no Captcha. Please refer this link. You need to add the user extension js file to your Selenium IDE and then use gotoIf function. Eg: Refer my script here. This will only prompt user to enter the Captcha if that element present.

Selenium Upload a file using button type and button tag instead of file

I have a webpage where I click on a button and an open dialog it's opened and I should select the file to upload. After that, a pop up is displayed saying OK or KO.
I'm able to upload files when the there are files types. But in this case, the element where I click it's:
<
button type="button" read-file="_.partial(submitLang, selectedLang)" id="import-lang" class="btn btn-default"><
/button>
For the rest of the application, I use this and it works:
WebElement element = getPage().findElementById(id);
element.sendKeys(absoluteFile);
But for button types and button tag it doesn't work.
How can I do it? The tests are running on a Linux machine
Thanks a lot!
More info!!
Hi all,
The whole process is: (see image at http://imageshack.com/a/img540/6237/JoTQng.png)
Click on Import button
A dialog is opened and I select a .json file and click Open
An alert is displayed saying "Text properties have been updated".
We are using angular for the frontend and all are REST calls.
We don't have any "file=type". All three are buttons. You can found more code at
http://imageshack.com/a/img633/7299/BQhP7o.png
For a file upload with selenium, you need to find an input tag with the type "file".
Have a look at your HTML and search for it.
When you found it, the rest is pretty straightforward:
Let's say this input-element has id="import"
driver.findElement(By.id("import")).sendKeys(absoluteFile);
If you run into problems, please post more of your HTML, then I can have a look at it.
In my case, clicking on the button made an element appear in the HTML code, I assume due to javascript.
I clicked on the element (which both opens a file upload window and adds the to the HTML), and immediately after send the keys to the input element.
This creates the problem of having to close the newly opened file upload window, however this is not a problem when using --headless mode on google chrome.
I do not have a solution to close this window if you are not in headless mode for your chosen browser.

Error in Selenium testcases while running

Using Selenium IDE, I recorded one testcase that contained a click url, then give the username and password and clicked the button to navigate to next page.
In the render page, if I click any link the error is shown as Element link=linkname not found.
Why does this error occur?
Page is fully loaded when that command is executing?
If not just put waitForPageToLoad or pause command.
waitForPageToLoad | timeout
Or
pause | 5000
Also you can use command clickAndWait for button after entering username and password
There are different ways via which you can handle such issues. The issues can be of rendering as username and password click is fine as you will rest on same page when you enter values in these test boxes.
But as soon as you click on submit button then application has to load a new page with the credentials you have just added.
So this requires some time in terms selenium. What you can do is you can put some waits just after this action. So far selenium provides two types of waits Explicit and Implicit waits.
And you can try thread.sleep() , its a java type of method which is also a kind of wait. But implicit and explicit waits are highly recommended in Selenium coding.
You can refer to this blog for more knowledge on waits (http://khyatisehgal.wordpress.com/2013/05/09/how-to-handle-timeouts-implicit-and-explicit-waits-in-selenium/)
Khyati Sehgal