java - Selenium and Junit, create a runnable jar for test the connection on a website -
i want make runnable jar test connection on website. pass parameters "$java -jar myjar.jar" shell command, parameters pseudo , pass want test.
so, have junit sample class entirely generated via selenium (plugin firefox)
checklog.java
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 checklog { 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://example.com/"; driver.manage().timeouts().implicitlywait(30, timeunit.seconds); } @test public void testl() throws exception { // tests } @after public void teardown() throws exception { driver.quit(); string verificationerrorstring = verificationerrors.tostring(); if (!"".equals(verificationerrorstring)) { fail(verificationerrorstring); } } private boolean iselementpresent(by by) { try { driver.findelement(by); return true; } catch (nosuchelementexception e) { return false; } } private boolean isalertpresent() { try { driver.switchto().alert(); return true; } catch (noalertpresentexception e) { return false; } } private string closealertandgetitstext() { try { alert alert = driver.switchto().alert(); string alerttext = alert.gettext(); if (acceptnextalert) { alert.accept(); } else { alert.dismiss(); } return alerttext; } { acceptnextalert = true; } } }
and main.java file
import java.io.console; import java.util.scanner; import org.junit.runner.junitcore; public class main { /** * @param args */ public static void main(string[] args){ if (args.length == 0){ console console = system.console(); string pseudo = new string(console.readline("pseudo : ")); string pass = new string(console.readpassword("pass : ")); } junitcore jcore = new junitcore(); jcore.run(checklog.class); } }
my question : how can pass parameters test class main class ? (like pseudo , pass)
~ upload ~
i :
(1) - can argument(s) shell command
and
(2) - can argument(s) main class (if don't pass argument shell command, jar ask argument(s) )
this post me way (1) https://stackoverflow.com/a/19530408/2137454 . but, maybe there way more proper ?
Comments
Post a Comment