When your page has onblur events to populate some of the data, it may not be triggered by Selenium's type command. In such cases, the blur event should be manually fired in our test case as follows
selenium.fireEvent("fieldname","blur");
2. To check the values displayed in the drop down field
selenium.isTextPresent("Values displayed in the field");
3. To check the values displayed in drop down coming from tables
List x = Methods();
StringBuilder stringbringprofilo_fisico = new StringBuilder( "default value");
for (int i = 0; i < class="code-object">String element = (String) x.get(i);
stringbringprofilo_fisico.append(" ");
stringbringprofilo_fisico.append(element);
}
String profilo_fisico = stringbringprofilo_fisico.toString();
System.out.println(profilo_fisico);
assertTrue(selenium.isTextPresent(profilo_fisico));
}
public List Methods()
{
Connection con = null;
String driver = "connection string";
// String s[] = null;
List al = new ArrayList();
try { Class.forName(driver);
con = DriverManager.getConnection("thin string", "user name", "password");
try { String query = "query";
PreparedStatement st = con.prepareStatement(query);
ResultSet res = st.executeQuery();
while (res.next())
{
al.add(res.getString("field name"));
con.close();
}
catch (SQLException sq)
{
e.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return al;
}
4. How to check the presence of the fields in the page that are displayed or hidden depending on other fields? When fields are hidden/shown dynamically, "assertEquals" function gives the same result whether the check box is enable or not. We can use "assertVisible" function to resolve this issue. But we have to check the presence of every field seperately. If you try to check more than one field using the above function, then you will get "ERROR: Element (names of the fields) not found"
5. How to check whether a button is disabled or enabled?
We can use the command To check for the presence of an enabled button
assertEquals("false", selenium.getAttribute("sm-event.ABCCliente-ABCSearchBase.StampaLettera@disabled"));
OR
verifyTrue(selenium.isEditable("sm-event.ABCCliente-ABCSearchBase.StampaLettera"));
To check for the presence of a disabled button
assertEquals("true", selenium.getAttribute("sm-event.ABCCliente-SearchBase.StampaLettera@disabled"));
OR
VerifyFalse(selenium.isEditable("sm-event.ABCCliente-ABCSearchBase.StampaLettera"));
Note:
in html format it is like
Command : assertAttribute
Target : ButtonName@disabled
Value : true or false
Please note that the parameter is the button name and not the button caption
input type="submit" name="sm-event.ABCCliente-ABCSearchBase.StampaLettera""Stampa Lettera" style="cursor:hand" class="Bottone"/ value=
6. How to run more than one test file?
Use the concept of JUnit TestSuite where you can group individual test cases into related Test suite.
import junit.framework.Test;
import junit.framework.TestSuite;
public class TestAll {
public static Test suite() {
TestSuite suite = new TestSuite("test all the scripts");
suite.addTestSuite(Testfile1.class);
suite.addTestSuite(Testfile2.class);
return suite;
}
}
We can add N no of Test files similarly. Run this file alone the remaining things selenium server will take care
7. How to ensure that the user session expires?
Sometimes, even after the window gets closed at the end of a test case, the user session still remains. So any subsequent operations starts from the previous logged on user. To avoid this, use
selenium.deleteAllVisibleCookies();
Sometimes, when the window is not closing properly, we can use
selenium.deleteAllVisibleCookies();
selenium.close();
The above fragment ensures that the session expires and the window closes.
8.How to get the read only field's value in a variable when the field has the jsp tag?
we can get the text or value displayed in jsp by
selenium.getTable("xpath of the field");
for example if you want to get a value displayed in a field otto cifre, in IDE record a field with the command "verify table" which will produce java command like
verifyEquals("54376383",selenium.getTable("//form/table\[1\]/tbody/tr/td/table.3.1"));
then change this command like
String Accountno = selenium.getTable("//form/table\[1\]/tbody/tr/td/table.3.1");
so that we can have the jsp value in ottoCifre variable.
No comments:
Post a Comment