public static void main(String[] args) throws JDOMException, IOException, TestCaseException { if (args.length == 0) { System.out.println("Please include a path for the selenium XML test file."); } else { SeleniumXml sel = new SeleniumXml(); for (String arg : args) { if (arg.startsWith("-username")) { sel.username = arg.substring(10); } else if (arg.startsWith("-password")) { sel.password = arg.substring(10); } else { sel.testSourcePath = arg; } } File testFile = new File(args[0]); if (testFile.exists()) { System.err.println(" Argument : " + args[0]); System.err.println(" Full absolute path of file : " + testFile.getAbsolutePath()); System.err.println(" Full canonical path of file : " + testFile.getCanonicalPath()); sel.testCaseDirectory = sel.getFileDirectory(testFile.getAbsolutePath()); System.err.println(" testCaseDirectory: " + sel.testCaseDirectory); sel.runTest(testFile.getAbsolutePath()); } else { System.err.println("Test File is not exist :" + args[0]); } } }
private void testcase(Element elem) { System.err.println("New testcase: " + elem.getAttributeValue("file")); String testFile = elem.getAttributeValue("file"); String isRun = replaceParam(elem.getAttributeValue("isRun")); String absolutePath = getAbsolutePath(testFile); String parentTestCase = new String(this.testCaseDirectory); SeleniumXml newTest = new SeleniumXml(this); newTest.testCaseDirectory = getFileDirectoryForRelativePath(absolutePath); try { if (isRun == null || isRun.equals("") || Boolean.valueOf(isRun)) { newTest.runTest(absolutePath); } else { System.err.println(" testFile :" + testFile + " isRun:" + isRun); } } catch (Exception e) { e.printStackTrace(); Assert.fail("Testcase error for file: " + absolutePath); } newTest.testCaseDirectory = parentTestCase; }
/* call run test suite from webtool selenium */ public static String runTestSuite(HttpServletRequest request, HttpServletResponse response) { Map parameters = UtilHttp.getParameterMap(request); String para = (String) parameters.get("testSuitePath"); if (para == null) { System.out.println("Error message : Test suite Path is null"); return "success"; } if (para.length() == 0) { System.out.println("Error message : Test suite Path is null"); return "success"; } try { URL url = UtilURL.fromResource("seleniumXml.properties"); if (props == null) { props = new Properties(); initConfig(url); } SeleniumXml sel = new SeleniumXml(); File testFile = new File(para.trim()); if (testFile.exists()) { System.err.println(" Argument : " + para.trim()); System.err.println(" Full absolute path of file : " + testFile.getAbsolutePath()); System.err.println(" Full canonical path of file : " + testFile.getCanonicalPath()); sel.testCaseDirectory = sel.getFileDirectory(testFile.getAbsolutePath()); System.err.println(" testCaseDirectory: " + sel.testCaseDirectory); sel.runTest(testFile.getAbsolutePath()); } else { System.err.println("Test File is not exist :" + para.trim()); } } catch (JDOMException jdome) { System.out.println(jdome.getMessage()); } catch (IOException ioe) { System.out.println("Error message : " + ioe.getMessage()); } finally { return "success"; } }
/** * Constructor to preset with an existing Map of parameters. Intended to be used for nested * Selenium tests. * * @param map */ public SeleniumXml(SeleniumXml selenium) { this.sel = selenium.getSelenium(); this.map = selenium.getParameterMap(); this.testCaseDirectory = selenium.testCaseDirectory; }