Command Line Arguments

301 views
Skip to first unread message

nka...@payoff.com

unread,
Oct 1, 2015, 6:13:38 PM10/1/15
to Galen Framework
Hi,

I have a requirement to see if I can add more command line arguments than the ones pre-defined.

e.g. galen test tests/sample.test.js --htmlreport reports/ --url https://google.com 

Can we do that?

Thanks,
Nitin

nka...@payoff.com

unread,
Oct 2, 2015, 1:24:36 PM10/2/15
to Galen Framework

I tried passing the command line argument:
galen test tests/login.test.js -DpageUrl="http://yahoo.com"
and when I try to access it in my test suite, I am calling:

var url = ${pageUrl};

I am getting an error: Exception in thread "main" java.lang.RuntimeException: org.mozilla.javascript.EvaluatorException: missing ; before statement

The -D option can only be used with .test file? My file is login.test.js.


How do we collect the command line argument in a variable in js file?

nka...@payoff.com

unread,
Oct 5, 2015, 2:22:18 PM10/5/15
to Galen Framework
So I tried to use it -D system property.
My command: galen test tests/login.test.js -Ddomain=yahoo.com

js file:

var domain = org.mozilla.javascript.System.getProperty("domain");

Error:
[pool-1-thread-1] ERROR com.galenframework.runner.EventHandler - Unknow error during executing test events.
org.mozilla.javascript.EcmaError: TypeError: Cannot call property getProperty in object [JavaPackage org.mozilla.javascript.System]. It is not a function, it is "object". (/tests/login.test.js) 

or I tried this command.
var domain = System.getProperty("domain");

[pool-1-thread-1] ERROR com.galenframework.runner.EventHandler - Unknow error during executing test events.
org.mozilla.javascript.EvaluatorException: Java class "[Ljava.lang.reflect.Constructor;" has no public instance field or method named "toJSON". (<cmd>#189)

Ivan/Contributors: An example of this will help with all the other wonderful examples you have posted.

Ivan Shubin

unread,
Oct 5, 2015, 4:00:23 PM10/5/15
to Galen Framework
Ok, so I figured this out. Actually the last line in your example works:

var domain = System.getProperty("domain");

What doesn't work is this

console.log(domain);

Because domain is actually a Java objects and console.log thinks that it is a JavaScript object.
So basically you have discovered a bug :) Thanks!
I just pushed a fix to master branch (https://github.com/galenframework/galen/commit/87793806b7e118ae812967326cd58d3d5f2d01b3), will soon make a minor release

But you can already use the property in your tests. It is just that you can't print it via console.log. 

nka...@payoff.com

unread,
Oct 5, 2015, 4:28:18 PM10/5/15
to Galen Framework
Awesome Ivan. Thanks I was able to make it work. Glad that you were able to fix the minor bug.

Reply all
Reply to author
Forward
0 new messages