- bharathip
- Posts : 8
Join date : 2011-11-08
How to avoid duplication of records in a database
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.
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.
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
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!");
}
- 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
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);
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);
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
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.
- bharathip
- Posts : 8
Join date : 2011-11-08
Re: How to avoid duplication of records in a database
Tue Nov 08, 2011 7:30 pm
id..i used id as locator..
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
Tue Nov 08, 2011 7:43 pm
OK, so you can also put into click() just "elementId".
For example:
For an element:
method will be look like:
When you don't set the type of locator, it is id by default.
This is simplification of the code
For example:
For an element:
- Code:
< in_put id="first-name" name="user-first-name" />
method will be look like:
- Code:
selenium.click("first-name");
When you don't set the type of locator, it is id by default.
This is simplification of the code
- bharathip
- Posts : 8
Join date : 2011-11-08
Re: How to avoid duplication of records in a database
Wed Nov 09, 2011 11:26 am
Still now my problem is not resolved yet.. can anyone help me..!!!!
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
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
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..
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..
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
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
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
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...
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...
- faramkaProfessional
- Posts : 143
Join date : 2011-09-15
Location : Poland
Re: How to avoid duplication of records in a database
Mon Nov 14, 2011 2:59 pm
OK, fine.
And thanks for sharing this solution
And thanks for sharing this solution
Permissions in this forum:
You cannot reply to topics in this forum