Best Galen code snippet using com.galenframework.actions.GalenActionTestArguments.parse
Source:ArgumentParserTest.java
1/*******************************************************************************2* Copyright 2017 Ivan Shubin http://galenframework.com3* 4* Licensed under the Apache License, Version 2.0 (the "License");5* you may not use this file except in compliance with the License.6* You may obtain a copy of the License at7* 8* http://www.apache.org/licenses/LICENSE-2.09* 10* Unless required by applicable law or agreed to in writing, software11* distributed under the License is distributed on an "AS IS" BASIS,12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13* See the License for the specific language governing permissions and14* limitations under the License.15******************************************************************************/16package com.galenframework.tests;17import static java.util.Arrays.asList;18import static org.hamcrest.MatcherAssert.assertThat;19import static org.hamcrest.Matchers.instanceOf;20import static org.hamcrest.Matchers.is;21import static org.hamcrest.Matchers.notNullValue;22import java.awt.Dimension;23import java.util.Collections;24import java.util.List;25import com.galenframework.actions.*;26import com.galenframework.runner.CombinedListener;27import org.apache.commons.cli.ParseException;28import org.apache.commons.lang3.ArrayUtils;29import org.testng.annotations.DataProvider;30import org.testng.annotations.Test;31public class ArgumentParserTest {32 private static final List<String> EMPTY_TAGS = Collections.emptyList();33 public static final CombinedListener NO_LISTENER = null;34 @Test35 public void shouldParseSystemProperties() throws ParseException {36 GalenAction.create("test",37 new String[]{".", "--htmlreport", "report", "-DsomeCustomVar=123", "-DsomeOtherVar=456", "-DpageUrl=http://example.com?q=1&w=2"},38 System.out, System.err, NO_LISTENER);39 assertThat(System.getProperty("someCustomVar"), is("123"));40 assertThat(System.getProperty("someOtherVar"), is("456"));41 assertThat(System.getProperty("pageUrl"), is("http://example.com?q=1&w=2"));42 }43 @Test(dataProvider = "goodSamples_testAction")44 public void shouldParse_testActionArguments(SimpleArguments args, GalenActionTestArguments expectedArguments) {45 String actionName = args.args[0];46 String[] arguments = ArrayUtils.subarray(args.args, 1, args.args.length);47 GalenActionTest action = (GalenActionTest) GalenAction.create(actionName, arguments, System.out, System.err, NO_LISTENER);48 assertThat(action.getTestArguments(), is(expectedArguments));49 }50 51 @DataProvider52 public Object[][] goodSamples_testAction() {53 return new Object[][]{54 {args("test", "mysuite", 55 "--recursive", 56 "--htmlreport", "some.html",57 "--testngreport", "testng.xml",58 "--jsonreport", "json-reports"59 ),60 new GalenActionTestArguments()61 .setPaths(asList("mysuite"))62 .setRecursive(true)63 .setHtmlReport("some.html")64 .setTestngReport("testng.xml")65 .setJsonReport("json-reports")66 .setIncludedTags(EMPTY_TAGS)67 .setExcludedTags(EMPTY_TAGS)},68 {args("test", "mysuite",69 "--groups", "mobile,tablet,homepage"),70 new GalenActionTestArguments()71 .setPaths(asList("mysuite"))72 .setGroups(asList("mobile", "tablet", "homepage"))73 .setRecursive(false)74 .setIncludedTags(EMPTY_TAGS)75 .setExcludedTags(EMPTY_TAGS)},76 {args("test", "mysuite",77 "--excluded-groups", "mobile,tablet,homepage"),78 new GalenActionTestArguments()79 .setPaths(asList("mysuite"))80 .setExcludedGroups(asList("mobile", "tablet", "homepage"))81 .setRecursive(false)82 .setIncludedTags(EMPTY_TAGS)83 .setExcludedTags(EMPTY_TAGS)},84 {args("test", "mysuite",85 "--htmlreport", "some.html",86 "--testngreport", "testng.xml"),87 new GalenActionTestArguments()88 .setPaths(asList("mysuite"))89 .setRecursive(false)90 .setHtmlReport("some.html")91 .setTestngReport("testng.xml")92 .setIncludedTags(EMPTY_TAGS)93 .setExcludedTags(EMPTY_TAGS)},94 95 {args("test", "mysuite", 96 "--htmlreport", "some.html",97 "--testngreport", "testng.xml",98 "--parallel-suites", "4"), 99 new GalenActionTestArguments()100 .setPaths(asList("mysuite"))101 .setRecursive(false)102 .setHtmlReport("some.html")103 .setTestngReport("testng.xml")104 .setIncludedTags(EMPTY_TAGS)105 .setExcludedTags(EMPTY_TAGS)106 .setParallelThreads(4)},107 108 {args("test", "mysuite", "mysuite2", 109 "--recursive", 110 "--htmlreport", "some.html",111 "--testngreport", "testng.xml"), 112 new GalenActionTestArguments()113 .setPaths(asList("mysuite", "mysuite2"))114 .setRecursive(true)115 .setHtmlReport("some.html")116 .setTestngReport("testng.xml")117 .setIncludedTags(EMPTY_TAGS)118 .setExcludedTags(EMPTY_TAGS)},119 120 {args("test", "mysuite", "mysuite2", 121 "--filter", "Some Test *"), 122 new GalenActionTestArguments()123 .setPaths(asList("mysuite", "mysuite2"))124 .setRecursive(false)125 .setFilter("Some Test *")126 .setIncludedTags(EMPTY_TAGS)127 .setExcludedTags(EMPTY_TAGS)},128 {args("test", "mysuite", "mysuite2", "--parallel-tests", "3"),129 new GalenActionTestArguments()130 .setPaths(asList("mysuite", "mysuite2"))131 .setRecursive(false)132 .setParallelThreads(3)133 .setIncludedTags(EMPTY_TAGS)134 .setExcludedTags(EMPTY_TAGS)},135 {args("test", "mysuite", "mysuite2", "--config", "/some/config"),136 new GalenActionTestArguments()137 .setPaths(asList("mysuite", "mysuite2"))138 .setRecursive(false)139 .setIncludedTags(EMPTY_TAGS)140 .setExcludedTags(EMPTY_TAGS)141 .setConfig("/some/config")142 },143 };144 }145 @Test(dataProvider = "goodSamples_simpleActions")146 public void shouldParse_simpleActions(String firstArg, Class<?>expectedType) {147 GalenAction action = GalenAction.create(firstArg, new String[]{}, System.out, System.err, NO_LISTENER);148 assertThat(action, is(instanceOf(expectedType)));149 }150 @DataProvider151 public Object[][] goodSamples_simpleActions() {152 return new Object[][] {153 {"config", GalenActionConfig.class},154 {"help", GalenActionHelp.class},155 {"-h", GalenActionHelp.class},156 {"--help", GalenActionHelp.class},157 {"version", GalenActionVersion.class},158 {"-v", GalenActionVersion.class},159 {"--version", GalenActionVersion.class}160 };161 }162 @Test163 public void shouldParse_dumpAction() {164 GalenActionDump action = (GalenActionDump) GalenAction.create("dump",165 new String[]{"my-page.gspec", "--url", "http://mindengine.net", "--export", "export-page-dir", "--max-width", "100", "--max-height", "150"},166 System.out, System.err, NO_LISTENER);167 assertThat(action.getDumpArguments(), is(new GalenActionDumpArguments()168 .setPaths(asList("my-page.gspec"))169 .setUrl("http://mindengine.net")170 .setExport("export-page-dir")171 .setMaxWidth(100)172 .setMaxHeight(150)));173 }174 @Test175 public void shouldParse_dumpAction_withConfig() {176 GalenActionDump action = (GalenActionDump) GalenAction.create("dump",177 new String[]{"my-page.gspec",178 "--url", "http://mindengine.net",179 "--export", "export-page-dir",180 "--max-width", "100",181 "--max-height", "150",182 "--config", "/some/config"183 },184 System.out, System.err, NO_LISTENER);185 assertThat(action.getDumpArguments(), is(new GalenActionDumpArguments()186 .setPaths(asList("my-page.gspec"))187 .setUrl("http://mindengine.net")188 .setExport("export-page-dir")189 .setMaxWidth(100)190 .setMaxHeight(150)191 .setConfig("/some/config")192 ));193 }194 @Test(dataProvider = "goodSamples_checkAction")195 public void shouldParse_checkActionArguments(SimpleArguments args, GalenActionCheckArguments expectedArguments) {196 String actionName = args.args[0];197 String[] arguments = ArrayUtils.subarray(args.args, 1, args.args.length);198 GalenActionCheck action = (GalenActionCheck) GalenAction.create(actionName, arguments, System.out, System.err, NO_LISTENER);199 assertThat(action.getCheckArguments(), is(expectedArguments));200 }201 @DataProvider202 public Object[][] goodSamples_checkAction() {203 return new Object[][]{204 {args("check", "some.spec",205 "--url", "http://mindengine.net",206 "--javascript", "some.js",207 "--include", "mobile,all",208 "--exclude", "nomobile,testTag",209 "--size", "400x700",210 "--htmlreport", "some.html",211 "--testngreport", "testng.xml",212 "--junitreport", "junit.xml"),213 new GalenActionCheckArguments()214 .setUrl("http://mindengine.net")215 .setJavascript("some.js")216 .setIncludedTags(asList("mobile", "all"))217 .setExcludedTags(asList("nomobile", "testTag"))218 .setScreenSize(new Dimension(400, 700))219 .setPaths(asList("some.spec"))220 .setHtmlReport("some.html")221 .setTestngReport("testng.xml")222 .setJunitReport("junit.xml")223 },224 {args("check", "some.spec",225 "--url", "http://mindengine.net",226 "--include", "mobile,all",227 "--exclude", "nomobile,testTag",228 "--size", "400x700",229 "--htmlreport", "some.html"),230 new GalenActionCheckArguments()231 .setUrl("http://mindengine.net")232 .setIncludedTags(asList("mobile", "all"))233 .setExcludedTags(asList("nomobile", "testTag"))234 .setScreenSize(new Dimension(400, 700))235 .setPaths(asList("some.spec"))236 .setHtmlReport("some.html")237 },238 {args("check", "some1.spec", "some2.spec", "--url", "http://mindengine.net"),239 new GalenActionCheckArguments()240 .setUrl("http://mindengine.net")241 .setPaths(asList("some1.spec", "some2.spec"))242 },243 {args("check", "some1.spec", "some2.spec", "--url", "http://mindengine.net", "--config", "/some/config"),244 new GalenActionCheckArguments()245 .setUrl("http://mindengine.net")246 .setPaths(asList("some1.spec", "some2.spec"))247 .setConfig("/some/config")248 },249 };250 }251 252 253 @Test(dataProvider="provideBadSamples")254 public void shouldGiveError_forIncorrectArguments(String expectedErrorMessage, SimpleArguments args) throws ParseException {255 IllegalArgumentException exception = null;256 try {257 String actionName = args.args[0];258 String[] arguments = ArrayUtils.subarray(args.args, 1, args.args.length);259 GalenAction.create(actionName, arguments, System.out, System.err, NO_LISTENER);260 }261 catch(IllegalArgumentException ex) {262 exception = ex;263 }264 265 assertThat("Exception should be", exception, is(notNullValue()));266 assertThat("Error message should be", exception.getMessage(), is(expectedErrorMessage));267 }268 269 @DataProvider270 public Object[][] provideBadSamples() {271 return new Object[][]{272 {"Incorrect size: 123", 273 args("check", "some.spec", "--url", "http://example.com", "--size", "123")},274 275 {"Incorrect size: 123xx123", 276 args("check", "some.spec", "--url", "http://example.com", "--size", "123xx123")},277 278 {"Incorrect size: a123xx123", 279 args("check", "some.spec", "--url", "http://example.com", "--size", "a123xx123")},280 281 {"Incorrect size: 123x", 282 args("check", "some.spec", "--url", "http://example.com", "--size", "123x")},283 284 {"Missing value for url",285 args("check", "some.spec", 286 "--url", 287 "--javascript", "some.js", 288 "--include", "mobile,all", 289 "--exclude", "nomobile,testTag", 290 "--size", "400x700", 291 "--htmlreport", "some.html")},292 293 {"Missing value for javascript",294 args("check", "some.spec", 295 "--url", "http://example.com", 296 "--javascript", 297 "--include", "mobile,all", 298 "--exclude", "nomobile,testTag", 299 "--size", "400x700", 300 "--htmlreport", "some.html")},301 302 {"Missing value for include",303 args("check", "some.spec", 304 "--url", "http://example.com", 305 "--javascript", "script.js", 306 "--include", 307 "--exclude", "nomobile,testTag", 308 "--size", "400x700", 309 "--htmlreport", "some.html")},310 311 {"Missing value for exclude",312 args("check", "some.spec", 313 "--url", "http://example.com", 314 "--javascript", "script.js", 315 "--include", "mobile", 316 "--exclude", 317 "--size", "400x700", 318 "--htmlreport", "some.html")},319 320 {"Missing value for size",321 args("check", "some.spec", 322 "--url", "http://example.com", 323 "--javascript", "script.js", 324 "--include", "mobile", 325 "--exclude", "nomobile", 326 "--size", 327 "--htmlreport", "some.html")},328 329 {"Missing value for htmlreport",330 args("check", "some.spec", 331 "--url", "http://example.com", 332 "--javascript", "script.js", 333 "--include", "mobile", 334 "--exclude", "nomobile", 335 "--size", "540x350", 336 "--htmlreport")},337 338 {"Missing spec files",339 args("check", 340 "--url", "http://example.com", 341 "--javascript", "script.js", 342 "--include", "mobile", 343 "--exclude", "nomobile", 344 "--size", "540x350")},345 346 {"Missing test files",347 args("test", 348 "--htmlreport", "reports")}349 };350 }351 private class SimpleArguments {352 private String[] args;353 private SimpleArguments(String...args) {354 this.args = args;355 }356 @Override357 public String toString() {358 StringBuffer buffer = new StringBuffer();359 for (String arg: args) {360 buffer.append(arg);361 buffer.append(" ");362 }363 return buffer.toString();364 }365 }366 private SimpleArguments args(String...args) {367 return new SimpleArguments(args);368 }369}...
Source:GalenActionTestArguments.java
...35 private String jsonReport;36 private List<String> groups;37 private List<String> excludedGroups;38 private String config;39 public static GalenActionTestArguments parse(String[] args) {40 args= ArgumentsUtils.processSystemProperties(args);41 Options options = new Options();42 options.addOption("i", "include", true, "Tags for sections that should be included in test run");43 options.addOption("e", "exclude", true, "Tags for sections that should be excluded from test run");44 options.addOption("h", "htmlreport", true, "Path for html output report");45 options.addOption("j", "jsonreport", true, "Path for json report");46 options.addOption("g", "testngreport", true, "Path for testng xml report");47 options.addOption("x", "junitreport", true, "Path for junit xml report");48 options.addOption("r", "recursive", false, "Flag for recursive tests scan");49 options.addOption("p", "parallel-tests", true, "Amount of tests to be run in parallel");50 options.addOption("P", "parallel-suites", true, "Amount of tests to be run in parallel");51 options.addOption("f", "filter", true, "Test filter");52 options.addOption("G", "groups", true, "Test groups");53 options.addOption("Q", "excluded-groups", true, "Excluded test groups");54 options.addOption("c", "config", true, "Path to galen config file");55 CommandLineParser parser = new PosixParser();56 CommandLine cmd;57 try {58 cmd = parser.parse(options, args);59 } catch (MissingArgumentException e) {60 throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e);61 } catch (Exception ex) {62 throw new RuntimeException(ex);63 }64 GalenActionTestArguments arguments = new GalenActionTestArguments();65 arguments.setIncludedTags(convertTags(cmd.getOptionValue("i", "")));66 arguments.setExcludedTags(convertTags(cmd.getOptionValue("e", "")));67 arguments.setTestngReport(cmd.getOptionValue("g"));68 arguments.setJunitReport(cmd.getOptionValue("x"));69 arguments.setRecursive(cmd.hasOption("r"));70 arguments.setHtmlReport(cmd.getOptionValue("h"));71 /*72 having this double check in order to have backwards compatibility with previous version73 in which the parallel tests used to be defined via --parallel-suites argument74 */75 if (cmd.hasOption("p")) {76 arguments.setParallelThreads(Integer.parseInt(cmd.getOptionValue("p", "0")));77 } else {78 arguments.setParallelThreads(Integer.parseInt(cmd.getOptionValue("P", "0")));79 }80 arguments.setFilter(cmd.getOptionValue("f"));81 arguments.setJsonReport(cmd.getOptionValue("j"));82 arguments.setGroups(convertTags(cmd.getOptionValue("G")));83 arguments.setExcludedGroups(convertTags(cmd.getOptionValue("Q")));84 arguments.setPaths(asList(cmd.getArgs()));85 arguments.setConfig(cmd.getOptionValue("c"));86 if (arguments.getPaths().isEmpty()) {87 throw new IllegalArgumentException("Missing test files");88 }89 return arguments;90 }91 public List<String> getPaths() {92 return paths;...
parse
Using AI Code Generation
1public class 1 {2 public static void main(String[] args) {3 GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();4 System.out.println(list);5 }6}7public class 2 {8 public static void main(String[] args) {9 GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();10 System.out.println(list);11 }12}13public class 3 {14 public static void main(String[] args) {15 GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();16 System.out.println(list);17 }18}19public class 4 {20 public static void main(String[] args) {21 GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();22 System.out.println(list);23 }24}25public class 5 {26 public static void main(String[] args) {
parse
Using AI Code Generation
1import com.galenframework.actions.GalenActionTestArguments;2public class 1 {3 public static void main(String[] args) {4 String[] parsedArguments = GalenActionTestArguments.parse(arguments);5 for(String string: parsedArguments){6 System.out.println(string);7 }8 }9}
parse
Using AI Code Generation
1GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();2String url = galenActionTestArguments.getUrl();3String size = galenActionTestArguments.getSize();4String browser = galenActionTestArguments.getBrowser();5GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();6String url = galenActionTestArguments.getUrl();7String size = galenActionTestArguments.getSize();8String browser = galenActionTestArguments.getBrowser();9GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();10String url = galenActionTestArguments.getUrl();11String size = galenActionTestArguments.getSize();12String browser = galenActionTestArguments.getBrowser();13GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();14String url = galenActionTestArguments.getUrl();15String size = galenActionTestArguments.getSize();16String browser = galenActionTestArguments.getBrowser();17GalenActionTestArguments galenActionTestArguments = new GalenActionTestArguments();18String url = galenActionTestArguments.getUrl();19String size = galenActionTestArguments.getSize();20String browser = galenActionTestArguments.getBrowser();
parse
Using AI Code Generation
1package com.galenframework.actions;2import org.testng.annotations.Test;3import java.util.List;4public class TestArguments {5 public void testParse() {6 String args = "testName: test1, test2, test3, test4, test5, test6, test7, test8, test9, test10";7 List<String> testNames = GalenActionTestArguments.parse(args, "testName");8 System.out.println(testNames);9 }10}
parse
Using AI Code Generation
1package com.galenframework.actions;2import com.galenframework.parser.SyntaxException;3import java.util.List;4public class GalenActionTestArguments {5 public static void main(String[] args) {6 String arguments = "arg1, arg2, arg3";7 try {8 GalenTestActionArguments galenTestActionArguments = GalenActionTestArguments.parse(arguments);9 List<String> inputArguments = galenTestActionArguments.getArguments();10 System.out.println("The arguments are: " + inputArguments);11 } catch (SyntaxException e) {12 e.printStackTrace();13 }14 }15}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!