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

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

Related

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.

Selenium IDE, selecting muliple text using same class

I have a page with lots of text using the same class. I am wanting to select and store all the text with that same class. Is this possible? All advice & comments appreciated!
I have HTML code like this:
<p class="foo">Some sample text</p>
<p class="foo">Some more sample text</p>
I have tried this:
<tr>
<td>storeText</td>
<td>//p[#class=foo']</td>
<td>var1</td>
</tr>
I expected var1 to be:
Some sample text
Some more sample text
Alternatively do I need to set up a while statement and gather each individually?
This page talks about a similar exercise, but uses Selenium for Python: Get the text from multiple elements with the same class in Selenium for Python?
//gather all p[class=foo]
List<WebElement> ele = driver.findElements(By.cssSelector("p.foo"));
Iterator<WebElement> iter = ele.iterator();
// initialize array, map, whatever
While(iter.hasNext()) {
// insert text into map
// print to log
// store in array
//whatever you need
var.add( iter.next().text() );
}
I didn't get to try out the answer from #bcar because I am not a javascript expert nor am I sure I could put the answer into IDE. I found another way however. I discovered that the text is stored in tables, so I am using the following code to extract the entire table (which includes the text I need).
<tr>
<td>storeText</td>
<td>//div/h2[text()="Elements and Performance Criteria"]/following::table</td>
<td>Content</td>
</tr>
Now I have to work out how to replace the new lines with as this is plain text. Another question for stackoverflow! Thanks.
Quite easy:
Just loop through the stored elements.
Whenever you use find_elements_by_class_name, it returns the list of selenium web elements. Hence you just need to iterate with a loop, like this.
names = driver.find_elements_by_class_name("_xEcR")
for i in names:
print(i.text)

Change reading order of html form elements

I'm designing a form like this, where the bottom of the labels in that row align in straight line and the top of the input fields in that row align in straight line.
Owing to some restriction in CSS (we can't fix the height as it will vary), I've to place the labels of the form elements in first row and then place their respective input fields in the next row (such that the input fields are placed just below their labels).
I tested the keyboard & the tab order with this html structure, it works fine.
I'm wondering that the reading order in JAWS or any other screen reader is not going to be right.
Any recommendations for any method to change the reading order
or
is it ok to go ahead with this html structure since the tab order is anywys working ?
In the HTML structure each input should be preceded by its label, rather than having labels on one row and inputs on the next.
However, you have a very particular display you want, and you are supporting IE7 (without display: table), so I think you are best off actually using a table.
You can do this accessibly, if you take these things into account:
Use a basic layout table for your form, and include an extra attribute on the table tag:
<table role="presentation">
That means the table is not a table from an accessibility point of view. (I only ever recommend this when supporting IE7 layouts!) Do not use <th> tags either.
The main thing for screen readers when filling it in would be an explicit label-input relationship.
<label for="input_id">My label</label>
<input type="text" id="input_id">
You can tell if this works by clicking on the label, it should put the cursor in the input.
However, your reading view needs a different approach. When you've got a row of items at the top that relate to a row of items underneath, that is the definition of a data table. So when the page is saved (or however it converts to the reading view), use a data table e.g:
<table>
<tr>
<th>Customer account number</th>
[other <th>s]
</tr>
<tr>
<tr>
<td>023456353434</td>
...
When read out by a screen reader it will read the 'header' (e.g. customer account number) before the content (023...). So the changes are:
Remove the role
Convert the top row into <th>s
It has to be said this is a hack, it is not particularly robust, and I certainly wouldn't recommend it for a responsive site. It is purely the required layout and browser support that lead to this.
without viewing your markup its impossible to tell exactly, but it sounds like you have a tow of inputs and then a row of labels....that's not ideal for accessibility.
you could nest the form control inside the label element, setting the form control's display to block to achieve the same effect, while also increasing usability and clickability.

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

Create an select option with selenium IDE

I have 2 selects for setting the expiration date on a credit card and I want to test that the error messaging comes back correctly when the card is expired. The only problem I have is that right now I can't pick a value that's expired since the list starts at Jan 2011 which isn't expired yet. What I'm thinking about doing is using javascript in selenium to inject a known expired value. Anyone have any idea on how to do this or suggestions on a better way to accomplish?
You can use the storeEval method to run snippets of JavaScript using Selenium. The JavaScript is run in the context of the Selenium object so you need window.document to get the document reference (hence the reason for the first line).
This snippet is the JavaScript for adding a new option the select element:
var d = window.document;
var select = d.getElementsByName("selectName")[0];
var option = d.createElement('option');
option.value='Value';
option.innerHTML='My new option';
select.appendChild(option);
Here's the copy/paste of my Selenium IDE entry for you.
<tr>
<td>storeEval</td>
<td>var d = window.document;var select = d.getElementsByName("selectName")[0];var option = d.createElement('option');option.value='Value';option.innerHTML='My new option';select.appendChild(option);</td>
<td></td>
</tr>
Then you can just have the standard select method in Selenium to select the option. Of course, you can always do option.setAttribute('selected',true) in the JavaScript snippet but having Selenium do it will ensure the new value has been selected (since it will fail if it can't find it).
storeEval
window.document.getElementsByName('descript')[0].value;
element