conversion from testng to jar in java shows error -
i have converted testng file jar creating class main , have main method inside
package uatframework; import org.testng.testlisteneradapter; import org.testng.testng; public class mainone{ public static void main(string[] args) { testlisteneradapter tla = new testlisteneradapter(); testng testng = new testng(); testng.settestclasses(new class[] { rms_login.class }); testng.addlistener(tla); testng.run(); } }
but rms_login class extends beforesftersuite class too. when run main java app->the browser opened , closed appears page doesnot load , error for:
@parameters({"susername","spassword","surl"}) public void uatrmslogintest(string susername, string spassword,java.lang.string surl) throws interruptedexception, ioexception { filewriter writer = new filewriter(file,true); string filename= "screenshots"; file filepath =new file(folderpath+"/" +filename); filepath.mkdirs(); if (system.getenv("surl") != null) { .... } }
as org.testng.testngexception: parameter 'susername' required @test on method uatrmslogintest has not been marked @optional or defined @ uatframework.mainone.main(mainone.java:13) ie testng.run in main method
the problem code not injecting required parameters @test
method expecting via @parameters
annotation.
here's code, contains working code.
import org.testng.itestnglistener; import org.testng.testlisteneradapter; import org.testng.testng; import org.testng.annotations.parameters; import org.testng.annotations.test; import org.testng.xml.xmlclass; import org.testng.xml.xmlsuite; import org.testng.xml.xmltest; import java.util.collections; public class mainone { public static void main(string[] args) { testlisteneradapter tla = new testlisteneradapter(); testng testng = new testng(); xmlsuite xmlsuite = new xmlsuite(); xmlsuite.getparameters().put("susername", "admin"); xmlsuite.getparameters().put("spassword", "admin"); xmlsuite.getparameters().put("surl", "http://localhost"); xmlsuite.setname("sample_suite"); xmltest xmltest = new xmltest(xmlsuite); xmltest.setname("sample_test"); xmltest.setclasses(collections.singletonlist(new xmlclass(rms_login.class))); testng.addlistener((itestnglistener) tla); testng.setxmlsuites(collections.singletonlist(xmlsuite)); testng.run(); } public static class rms_login { @parameters({"susername", "spassword", "surl"}) @test public void uatrmslogintest(string susername, string spassword, string surl) { //since don't know method supposed do, //just printing them out. system.err.println("username " + susername); system.err.println("password " + spassword); system.err.println("url " + surl); } } }
here's output
username admin password admin url http://localhost =============================================== sample_suite total tests run: 1, failures: 0, skips: 0 ===============================================
Comments
Post a Comment