i'm using testng , selenium in eclipse, in java. have method test calls other methods support actions needs perform. have them marked part of test using @test.
@beforetest public void beforetest() { driver.manage().window().maximize(); } @test public static void checkvalidity(string[] array, webdriver driver){ string partialurl = ""; int brokenlinks = 0; (int x=1; x<array.length; x+=2){ partialurl = anonusersitemapexperience.getpartialurl(driver, array[x]); if (partialurl.isempty()){ system.err.println("the link \""+array[x]+"\" intended "+array[x-1]+" page either broken or external site."); brokenlinks++; brokenlinkstot++; } else{ int found = anonusersitemapexperience.findmatch(array, array.length, partialurl); if (found<1){ system.err.println("a match not found "+array[x-1]+".\n"+array[x]+"\n"+partialurl); brokenlinks++; brokenlinkstot++; } } } system.err.println("\n"+brokenlinks+" broken link(s) was/were found.\n"); } @test public static void opendropdowns(webdriver driver){ list<webelement> dropdownarrows = driver.findelements(by.classname("dropdowntoggler")); iterator<webelement> itr = dropdownarrows.iterator(); while(itr.hasnext()){ try{ itr.next().click(); } catch(elementnotvisibleexception e){ } } } @test public static string[] createarray(list<webelement> list){ string[] linkarray = new string[list.size()*2]; int counter = 0; (int x=1; x<linkarray.length; x+=2){ linkarray[x] = list.get(counter).getattribute("href"); try{ linkarray[x] = linkarray[x].replaceall("%c2%ae", "®"); linkarray[x] = linkarray[x].replaceall("%20", " "); linkarray[x] = linkarray[x].replaceall("%27", "'"); linkarray[x] = linkarray[x].replaceall("%c3%a4", "ä"); linkarray[x] = linkarray[x].replaceall("%c3%b6", "ö"); linkarray[x] = linkarray[x].replaceall("%c3%bc", "ü"); linkarray[x] = linkarray[x].replaceall("%c3%84", "Ä"); linkarray[x] = linkarray[x].replaceall("%c3%96", "Ö"); linkarray[x] = linkarray[x].replaceall("%c3%9c", "Ü"); linkarray[x] = linkarray[x].replaceall("%e2%80%93", "–"); linkarray[x] = linkarray[x].replaceall("%e2%84%a2", "™"); linkarray[x] = linkarray[x].replaceall("%25", "%"); counter++; } catch(exception e){ } } int counter2 = 0; (int x=0; x<linkarray.length; x+=2){ linkarray[x] = list.get(counter2).gettext(); counter2++; } return linkarray; } @test public void test() { driver.get(siteus); list<webelement> topnavlinks = driver.findelement(by.classname("topnavigationmenu")).findelements(by.classname("menulink")); int numlinks = topnavlinks.size(); string[] topnavtitlesandlinks = new string[numlinks*2]; topnavtitlesandlinks = createarray(topnavlinks); system.out.println("filled titles , links array."); (int x=1; x<topnavtitlesandlinks.length; x+=2){ driver.get(topnavtitlesandlinks[x]); opendropdowns(driver); try{ list<webelement> menu = driver.findelement(by.classname("asidenavigationmenu")).findelements(by.classname("itemlink")); string[] menuarray = new string[menu.size()*2]; menuarray = createarray(menu); checkvalidity(menuarray, driver); } catch (exception e){ if (topnavtitlesandlinks[x-1].contains("endodontics")){ webelement element = driver.findelement(by.linktext("endodontics")); actions action = new actions(driver); action.movetoelement(element).perform(); webelement subelement = driver.findelement(by.partiallinktext("access")); action.movetoelement(subelement); action.click(); action.perform(); opendropdowns(driver); list<webelement> menu = driver.findelement(by.classname("asidenavigationmenu")).findelements(by.classname("itemlink")); string[] menuarray = new string[menu.size()*2]; menuarray = createarray(menu); checkvalidity(menuarray, driver); } } } } @aftertest public void aftertest() { driver.close(); driver.quit(); system.err.println("\ntotal broken links found: "+brokenlinkstot); long time2 = system.currenttimemillis(); double timemin =((double)(time2-time1)/60000); int timemintrunc = (int)timemin; double timesec = (timemin%1)*60; system.out.println("\n\nall tests finished in "+timemintrunc+" minutes , "+timesec+" seconds."); } problem is, when run it, don't pass fails methods called test. output follows:
failed: test
skipped: checkvalidity
skipped: opendropdowns
so how can make of called methods report well?
- non-void methods ignored testng
- you should not call test methods - job testng
- rewrite test class methods annotated
@testreflect scenario , follow in row. can use helper methods want.
e.g.
@beforeclass public void before() { //blah blah precondition goes here } @test(priority=0) public void start() { // testy test 0 goes here } @test(dependsonmethods = "start") public void next() { sysout(dosomething()); } public string dosomething() { return "helper method call in test method"; } upd
if want invoke 400 times:
@dataprovider(name = "400_links") public static string[][] getlinks() { // find own way create links here return new string[][] {{"http://foo"}, {"http://bar"}, ... , {"http://xyz"}}; } @test(dataprovider = "400_links") public void checkalllinks(string link) { checkvalidityorwhatever(link); } public void checkvalidityorwhatever(string link) { //blah blah http ftw } it launched 400 times, if have 400 links provided in getlinks() every iteration reported testng. failed iterations not stop other invocations launch.
Comments
Post a Comment