Database Transaction using Robotium -
heloo all,
i automating product developed using robotium. able cope many of modules. thing need hardcode validations like:
if username "xyz" password has "12345". on hardcoding,the values in-
solo.entertext(0,"xyz"); solo.entertext(1,"12345");
this works fine. want know if there way in can query database being used, values there , make solo class validate tests.
any solution , example problem highly appreciated.
follow below steps achieve this,
step: 1. read values database , store in xml.
class.forname(sun.jdbc.odbc.jdbcodbcdriver).newinstance(); connection con = drivermanager.getconnection(jdbc:odbc:mydata, “”, “”); statement stmt = con.createstatement(); string query = “select username, password customers”; resultset rs = stmt.executequery(query); stringbuffer xml = “<?xml version=‘1.0’?><mydatabase><customers>”; while (rs.next()) { xml.append(“<custrec><custusername>”); xml.append(rs.getstring(“username”)); xml.append(“</custname><cuspassword>”); xml.append(rs.getint(“password”)); xml.append(“</custpassword></custrec>”); } xml.append(“</customers></mydatabase>”);
step: 2. read values xml file , use in solo
class.
.
stringreader stringreader = new stringreader(xmlstring); inputsource inputsource = new inputsource(stringreader); domparser domparser = new domparser(); domparser.parse(inputsource); document document = domparser.getdocument(); nodelist usernamelist = doc.getelementsbytagname(“custusername”); nodelist passwordlist = doc.getelementsbytagname(“custpassword”);
Comments
Post a Comment