Selenium IDE sendKeys doesn't trigger the js validation function on number fields - selenium-ide

I am trying to test if a validation error shows up when the user types a number into a number field that is not a whole number. The error appears when I type it into the field manually, but when I run it in selenium, the js is never triggered so the error doesn't show on the screen and the test fails.
<tr>
<td>type</td>
<td>//*[#id='notificationTimerNum']</td>
<td></td>
</tr>
<tr>
<td>sendKeys</td>
<td>//*[#id='notificationTimerNum']</td>
<td>1.5</td>
</tr>
<tr>
<td>waitForVisible</td>
<td>//*[contains(#class, 'control-error')]//*[contains(., 'The number of minutes must be entered as a whole number')]</td>
<td></td>
I have also tried using the fireEvent command as suggested here with no luck.
In addition, I am unable to run Selenium IDE sendKeys on my local browser outside of the test environment because it errors out on sendKeys when trying to type a value into the number field.
[error] Unexpected Exception: Error: Cannot set the selection end.

I've experienced the same issue, in some cases, you have to send a keypress to the field AFTER you've entered the text, so after your sendKeys command with the number, do another one right after to send either a tab or enter keypress.
sendKeys | //*[id=notificationTimerNum] | ${KEY_TAB} (or ${KEY_ENTER})
For me, that "triggers" the validation of the data in the field, and you can then do the waitForVisible for the error message.
Klendathu

Related

How to catch table text value with querySelector

I'm trying to catch a text line within a table. I've very close. When I'm entering the following line document.querySelectorAll(“td”)[3] in the console dev tool it return me this
<td align="right"> $65.00 </td>
However how do I get the $65.00 value ?
When I'm using document.querySelectorAll(“td”)[3].textContent it not always working, sometimes I have a SyntaxError sometimes I have the value...
document.querySelectorAll("td")[3].textContent
You can just access innerText attribute and you will be returned a string with the required value
document.querySelectorAll("td")[3].innerText
This should give you the desired value

How to do a regexp in a waitForPopUp Command in Selenium IDE?

I have popups with this name structure:
static_dynamic_static
The dynamic part changes each time I log in so my test cases fail each time. I thought about solving the problem with a regular expression like this:
Command: waitForPopUp
Target: regexp:static_.+_static
But this doesn't work. What do I do wrong? Is this even working. If not, is there another way to solve this problem?
From my experience you don't need to declare it as a regex within the target field, you should just be able to have the target as:
static_*_static
and that should do it
If you've got only one popup window you can use null as a target and test will take the first popup:
waitForPopup | null
The other option is to get dynamic part before popup opening. It is very likely that the dynamic part could be retrieved from the page. If so you can get it using storeEval, and than use like:
waitForPopup | javascript{'static'+storedVars['dynamic']+'static'}
If you can't store the dynamic part please provide an html of your page or only the part where the dynamic part mentioned.
I see that theoretically it could be possible to get all the names of your windows and than to use pattern in a loop to get the one.
Also (theoretically) it is possible to expand default waitForPopup function.
But the second way and especially the first are much cheaper.
The best way to handle this might be to run a snippet of javascript to handle this:
<tr>
<td>storeEval</td>
<td>var myRe = new RegExp("^prefix.+", "g"); var mywin; windows=selenium.getAllWindowNames();for (i = 0; i < windows.length; i++) { if(myRe.test(windows[i])) { mywin=windows[i]} }; mywin;</td>
<td>x</td>
</tr>
<tr>
<td>selectWindow</td>
<td>name=${myWindow}</td>
<td></td>
</tr>
That javascript isn't fully function (no null checking) but should help get you on the right track.

How to run a test case in selenium IDE which requires user to fill in certain details

I am new to Selenium and exploring the IDE currently. I am supposed to automate a web page which requires user to fill in a row of details(It is a row of fields which asks user to fill in name,email ID , to and from dates etc).
I have created a test case and filled in all these details(recorded in IDE). When I play the test case, I observe that the details I have filled appears below the row and the IDE trying to fill in the same values. It errors out telling Name and email ID exist.
Is there anyway I can test this case successfully? I do not have access to the code nor the database.
Sounds like you need to create with new user info each time. I tend to use javascript to create a unique timestamped e-mail...
<tr>
<td>storeEval</td>
<td>'myemail' + Date.now() + '#testdomain.com'</td>
<td>emailAddress</td>
</tr>
<tr>
<td>echo</td>
<td>${emailAddress}</td>
<td></td>
</tr>
Sounds like an issue with duplicate details, the data appearing below the entry field will most likely be just auto complete. But from what you've described I think you'd need to use different data each time.
SeLite is a useful plugin that has an additional extension to it called SeLite Commands, which gives you extra commands which will input random data into fields (if you don't have any specific requirements on the data being input) it can generate random text, or random emails as well.
Both can be downloaded from here

jQuery Traversing + Live Event Handlers

I'm having some issues with attaching live event handlers to particular rows.
What I have and what I'm after:
I have some HTML that will be generated dynamically after page load as follows:
<table>
<tr>
<td></td>
</tr>
<tr>
<td class="bonus"></td>
</tr>
<tr>
<td></td>
</tr>
</table>
I would like to have two click events:
One for rows that aren't a "bonus row"
One for rows that have a "bonus row" after them
What I've tried and the problem:
However, I cannot work out how to use a selector to select "element that has a particular element after it" (i.e. a "previous" selector). As such, the best I can arrive at is:
Rows that aren't a "bonus row": $('tr:not(:has(.bonus))')
Rows that have a "bonus row" after them: $('tr + tr:has(.bonus)').prev()
This is all well and good, except whenever I use the live() method on a jQuery object that was obtained through traversal, rather than pure selection i.e.
$('tr:has(.bonus)').prev().live('click', function() {
alert('hello');
});
I get this error:
uncaught exception: Syntax error,
unrecognized expression: )
The issue as an even more minimal example:
I was hoping this was localised to some script I am using, but I've isolated this to a minimal jsFiddle example which still replicates the issue for me: http://jsfiddle.net/ptvrA/
HTML:
<div></div>
<div id="target"></div>
JS:
$('#target').prev().live('click', function () {
alert('f');
});
It seems from this answer that this is a known limitation of live.
My workarounds
For reference, my workarounds are either:
Mark the rows that have a "bonus row" after them in some way
Bind the click to all rows, and do a check to see if there is a "bonus row" after them within the handler.
But if I can get a "nicer" solution, even out of curiosity in case I run into this problem in a different situation, I'd appreciate it.
Cheers
$('tr + tr:has(.bonus) ~ tr') //for row whose next sibling is a bonus row
Will do what you want with the .live method.
For all the people who get here in the future using google.
uncaught exception: Syntax error, unrecognized expression: )
That is happening because .live() uses the original selector that was given to the first call in the jQuery chain. It doesn't no consider additional methods used after the initial $('selector').
To be honest, I'd just use your second idea and bind click to all rows, then check to see if next row has a bonus td in it, like this:
$('tr:not(:has(.bonus))').live('click', function () {
if ($(this).next().children('td').hasClass('bonus')) {
alert('next row has bonus td');
}
else {
alert('next row does not have bonus td');
}
});
fiddle located here: http://jsfiddle.net/7gdqc/2/
I don't think there's a pure selector way to do it, and this isn't really a workaround - I'd call it a valid solution to your problem.

Selenium IDE - registration test (trying to get a pass on the automation part)

I have a quick question, I looked around the site and was not able to find another question relevant to what I wanted to ask. I am trying to implement Selenium IDE and use it agiants a company website. I want to be able to record a registration and then have the registration play back. The problem I run into is when the test is played back it always fails. The reason is becase the account cannot be re-created again. Is there a way I can get the test to pass after I have recorded a registration process?
this works for me to create a random email id-
<tr>
<td>storeEval</td>
<td>Math.round (Math.random() * 1357)</td>
<td>random</td>
</tr>
<tr>
<td>type</td>
<td>email</td>
<td>selenium${random}#domain.com</td>
</tr>
To create a random user
<tr>
<td>storeEval</td>
<td>Math.round (Math.random() * 1357)</td>
<td>random</td>
</tr>
<tr>
<td>type</td>
<td>user</td>
<td>selenium${random}</td>
</tr>
The problem is not with your Selenium test, but with the page itself. If you are trying to register the same user again, it is actually expected to fail - you might even record test that validates it.
You have to options - either clean the database so that the test always runs on the same data set or make your script more intelligent. The first option requires you to have full access to tested site (which is usually the case) but you can safely assume that the test results are predictable most of the time.
On the other hand by making the tests more intelligent I meant using random user name (or generating unique name some other way) - more coding and I am not sure whether it is possible with plain Selenium IDE.
You can generate random data while execution of scripts for email/name
Username/ID:- javascript{Math.floor(Math.random()*11)}
--- increased number of digit by increasing number of 1
Email :- javascript{"abc+" + Math.floor(Math.random()*11111) + "#gmail.com";}
Yaasir,
The Selenium IDE gladly executes JavaScript. That means, you may use not only Math.random, but also something that generates more unique identifier.
I am using all the way the timestamp. This is easy and the result is so unique, you would not possibly get same number unless you reset time on your test machine ( in that case possibility of getting same identifier becomes slightly bigger than zero).
Here is the line I use
<tr>
<td>store</td>
<td>javascript{new Date().getTime()}</td>
<td>timestamp</td>
</tr>
As a result, you will get similar to this number 1375400227202