java - How do I use enums together with command line arguments? -
this question has answer here:
- lookup enum string value 22 answers
public class webdriver2 { public enum env { qa, stage, prod, dev } public static class environment { env env; public environment(env env) { this.env = env; } public void chooseenvironment() { file file = new file("h:\\internstuff\\selenium\\iedriverserver.exe"); system.setproperty("webdriver.ie.driver", file.getabsolutepath() ); webdriver driver = new internetexplorerdriver(); switch(env) { case qa: driver.get("http://****/qa_was8.html"); break; case stage: driver.get("http://***/stage.html"); break; case prod: driver.get("http://****/prod.html"); break; case dev: driver.get("http://***/index.html"); break; default: string[] links; links = new string[4]; links[0]= "http://****/qa_was8.html"; links[1]= "http://***/stage.html"; links[2]="http://****/prod.html"; links[3]="http://****/index.html"; for(int = 0; i<links.length;i++) { driver.get(links[i]); } } } } public enum app { accountinventory , auditactionitems } public static class application{ app app; public application(app app) { this.app = app; } public void chooseapp() { file file = new file("h:\\internstuff\\selenium\\iedriverserver.exe"); system.setproperty("webdriver.ie.driver", file.getabsolutepath() ); webdriver driver = new internetexplorerdriver(); switch(app) { case accountinventory: driver.get("http://***/qa_was8.html"); driver.findelement(by.linktext("account inventory")).click(); driver.findelement(by.name("j_username")).sendkeys("****"); driver.findelement(by.name("j_password")).sendkeys("***"); driver.findelement(by.cssselector("input[type='submit']")).click(); try { timeunit.seconds.sleep(5); } catch (interruptedexception e1) { e1.printstacktrace(); } driver.findelement(by.classname("inputtext")).sendkeys("smith"); driver.findelement(by.classname("commandexbutton")).click(); break; case auditactionitems: driver.get("http://***/qa_was8.html"); driver.findelement(by.linktext("auditaction items")).click(); driver.findelement(by.name("j_username")).sendkeys("***"); driver.findelement(by.name("j_password")).sendkeys("***"); driver.findelement(by.cssselector("input[type='submit']")).click(); try { timeunit.seconds.sleep(5); } catch (interruptedexception e1) { e1.printstacktrace(); } driver.findelement(by.classname("commandexbutton")).click(); default: system.out.println("enter app name"); } } } public static void main(string[] args) { } }
i working in eclipse , making selenium webdriver , need able use command line parameter give application name , environment name (both enums) , run test. know need put in eclipse argument box run | run configurations | arguments not sure what. appreciated.
try:
public static void main(string[] args) { try { app argarg = app.valueof(args[0]); env argenv = env.valueof(args[1]); } catch(illegalargumentexception e) { printhelp(); system.exit(1); } ... }
in printhelp()
can list possible values with:
stringbuffer appparamhelp = new stringbuffer("possible 'app' values are:"); for(app possibleappval : app.values) { appparamhelp.append(" "); appparamhelp.append(possibleappval.name()); }
Comments
Post a Comment