Share
Go down
bharathip
Posts : 8
Join date : 2011-11-08

How to avoid duplication of records in a database

on Tue Nov 08, 2011 3:44 pm
Hi all,
I am using selenium RC with testng. writing scripts in java.
i m testing a web application. In that duplication of a record is not allowed.
I am passing records through xls using data provider.

In the application, if we enter same name for another record and click on another field,it will show a message that record already exists..!! on the top of the field name itself.
when i use istextpresent(); it is not detecting that msg while running the test Script..
and allowing duplication of records. i found two records with same content in database after running test script.

can any one tell me how to resolve this issue.


Last edited by bharathip on Wed Nov 09, 2011 11:33 am; edited 1 time in total
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Tue Nov 08, 2011 5:18 pm
How exactly do you use isTextPresent() ? You should use it with if statement (for my code in PHP with PHPUnit):
Code:
if ($this->isTextPresent("Record already exists!") {
    $this->fail("Attempt to duplicate the record!");
}
Another way you can do it with using assertElementNotPresent() and try/catch:
Code:
try {
        $this->assertTextNotPresent("Record already exists!") {
} catch (Exception $e) {
        $this->fail("Attempt to duplicate the record!");
}
bharathip
Posts : 8
Join date : 2011-11-08

Re: How to avoid duplication of records in a database

on Tue Nov 08, 2011 6:13 pm
Screen consists of two fields Name and Remarks
Entered name field, and clicked on remarks field. If name already exists a warning appears above the name field "name already exists..!!"
but while running test script that warning is not getting generated by clicking on remarks field.
//Below is my code.//

selenium.type("id=name field id",name);
selenium.click(" fieid=remarksld id",remarks );

if(selenium.isTextPresent("Name already exists"))
{
throw new SkipException("Record already exists..!!");
}
selenium.type("fieid=remarksld id",remarks);

faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Tue Nov 08, 2011 7:27 pm
bharathip wrote:selenium.click(" fieid=remarksld id",remarks );

At first you should change the above line, because click() takes one parameter (element's locator in the following form: locatorType=argument). And could you please tell what type of locator do you try to use by writing fieid? As I know, there are locators: id, identifier, name, dom, xpath, link, css.


Last edited by faramka on Tue Nov 08, 2011 7:30 pm; edited 1 time in total
bharathip
Posts : 8
Join date : 2011-11-08

Re: How to avoid duplication of records in a database

on Tue Nov 08, 2011 7:30 pm
id..i used id as locator..
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Tue Nov 08, 2011 7:43 pm
OK, so you can also put into click() just "elementId".
For example:
For an element:
Code:
< in_put id="first-name" name="user-first-name" />
(I added "_" to set this code as text)
method will be look like:
Code:
selenium.click("first-name");
d
When you don't set the type of locator, it is id by default.

This is simplification of the code Smile


Last edited by faramka on Tue Nov 08, 2011 7:47 pm; edited 1 time in total (Reason for editing : (I added "_" to set this code as text))
bharathip
Posts : 8
Join date : 2011-11-08

Re: How to avoid duplication of records in a database

on Wed Nov 09, 2011 11:26 am


Still now my problem is not resolved yet.. can anyone help me..!!!!


Sad
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Wed Nov 09, 2011 8:02 pm
Maybe after putting a text in name field you should click outside the name field and then check if there a message is displayed.
bharathip
Posts : 8
Join date : 2011-11-08

Re: How to avoid duplication of records in a database

on Thu Nov 10, 2011 11:08 am
If i click out the field manually, Text is appearing.

Through automation it is not working.Warning text itself is not appearing. How can selenium can detect the text..?
I am not able to understand what i should do..
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Thu Nov 10, 2011 2:22 pm
Try click not manually but by simulating with Selenium!

1. type a text in name field
2. click at any other element
3. verify if the message is displayed
bharathip
Posts : 8
Join date : 2011-11-08

Re: How to avoid duplication of records in a database

on Fri Nov 11, 2011 12:18 pm
I got the solution for this...

After the entering the name , performing click operation on the other field through selenium. that warning is not appearing.

use -> selenium.fireEvent("id of the name field","onblur");

Write the above statement after entering the name in selenium test script.

thank u... Very Happy
faramka
Professional
Professional
Posts : 143
Join date : 2011-09-15
Location : Poland

Re: How to avoid duplication of records in a database

on Mon Nov 14, 2011 2:59 pm
OK, fine.
And thanks for sharing this solution Smile
Sponsored content

Re: How to avoid duplication of records in a database

Back to top
Permissions in this forum:
You cannot reply to topics in this forum