java - After Generating webdriver code ,how and where to modify code -
java - After Generating webdriver code ,how and where to modify code -
i newbie selenium test cases, uncertainty roam between generated web driver code(java ;j-unit) , how run code changes in code , found errors in project
before may know want made alter in code ,what generated already.
for eaxmple :
i recorded login form page, generated java/junit 4/webdriver code verify link button selenium ide , import bundle eclipse...
i add together features or changes in login form , purpously forget maintain link button
using selenium test generated before java/junit 4/webdriver code , want print o/p as"link button not found"
bundle web; //import java.util.regex.pattern; import java.util.concurrent.timeunit; import org.junit.*; import static org.junit.assert.*; //import static org.hamcrest.corematchers.*; import org.openqa.selenium.*; import org.openqa.selenium.firefox.firefoxdriver; //import org.openqa.selenium.support.ui.select; public class webdriver { private webdriver driver; private string baseurl; //private boolean acceptnextalert = true; private stringbuffer verificationerrors = new stringbuffer(); @before public void setup() throws exception { driver = new firefoxdriver(); baseurl = "http://localhost/"; driver.manage().timeouts().implicitlywait(10, timeunit.seconds); } @test public void testuntitled() throws exception { driver.get(baseurl + "/crm/default.aspx"); driver.findelement(by.id("loginmain_username")).clear(); driver.findelement(by.id("loginmain_username")).sendkeys("admin"); driver.findelement(by.id("loginmain_password")).clear(); driver.findelement(by.id("loginmain_password")).sendkeys("xxx"); seek { asserttrue(iselementpresent(by.id("loginmain_usernamelabel"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("loginmain_passwordlabel"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("loginmain_username"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("loginmain_password"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("loginmain_loginbutton"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("linkbuttonregister"))); } grab (error e) { verificationerrors.append(e.tostring()); } driver.findelement(by.id("loginmain_loginbutton")).click(); seek { assertequals("webdriver testingest.,", driver.gettitle()); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("ctl00_ctl00_imagebutton1"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.id("ctl00_ctl00_imagebutton2"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.linktext("home"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.linktext("sales"))); } grab (error e) { verificationerrors.append(e.tostring()); } seek { asserttrue(iselementpresent(by.linktext("masters"))); } grab (error e) { verificationerrors.append(e.tostring()); } } @after public void teardown() throws exception { driver.quit(); string verificationerrorstring = verificationerrors.tostring(); if (!"".equals(verificationerrorstring)) { fail(verificationerrorstring); } } private boolean iselementpresent(by by) { seek { driver.findelement(by); homecoming true; } grab (nosuchelementexception e) { homecoming false; } }
to want want should modify:
try { asserttrue("link button not found",iselementpresent(by.id("linkbuttonregister"))); } grab (error e) { //add here log message if necesary system.out.println("link button not found"); verificationerrors.append(e.tostring()); }
hope help!
java eclipse testing junit selenium-webdriver
Comments
Post a Comment