getgauge / gauge-java Goto Github PK
View Code? Open in Web Editor NEWJava runner for Gauge
Home Page: https://gauge.org
License: Apache License 2.0
Java runner for Gauge
Home Page: https://gauge.org
License: Apache License 2.0
I have a use case that requires a consistent connection for each step, and for that connection to live for the life of the spec. The obvious approach of having the connection be a part of the step implementation as an instance variable seems to cause problems since @BeforeSpec
and @AfterSpec
get called on different instances.
Due to upstream library dependencies, the connection MUST be closed or it caused all sorts of problems/race-conditions.
Example:
@BeforeSpec
public void connectToMainframe() throws Exception {
this.mainframe = Mainframe.connectTo("<host>", 30072);
}
@AfterSpec
public void disconnectFromMainframe() throws Exception {
this.mainframe.disconnect();
}
Expose APIs similar to java's print() and println() so that a user can control if the messages go into a new line on the report.
Reported by @henkbl at getgauge/gauge#228 and @vshanve at getgauge/gauge#222.
Stacktrace:
09:17:26.196 [INFO] 1 [main] WARN org.reflections.Reflections - could not create Dir using com.thoughtworks.gauge.scan.ClasspathScanner$1@49b96230 from url file:/Users/.gauge/plugins/java/0.3.1/. skipping.
java.lang.NullPointerException
at com.thoughtworks.gauge.scan.ClasspathScanner$1.createDir(ClasspathScanner.java:53)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:99)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
at org.reflections.Reflections.scan(Reflections.java:237)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.(Reflections.java:129)
at com.thoughtworks.gauge.scan.ClasspathScanner.createReflections(ClasspathScanner.java:60)
at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:37)
at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:36)
09:17:26.196 [INFO] 3 [main] WARN org.reflections.Reflections - could not create Dir using directory from url file:/Users/.gauge/plugins/java/0.3.1/. skipping.
java.lang.NullPointerException
at org.reflections.vfs.Vfs$DefaultUrlTypes$3.matches(Vfs.java:239)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:98)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
at org.reflections.Reflections.scan(Reflections.java:237)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.(Reflections.java:129)
at com.thoughtworks.gauge.scan.ClasspathScanner.createReflections(ClasspathScanner.java:60)
at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:37)
at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:36)
09:17:26.196 [INFO] 3 [main] WARN org.reflections.Reflections - could not create Vfs.Dir from url. ignoring the exception and continuing
org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/Users/.gauge/plugins/java/0.3.1/*]
either use fromURL(final URL url, final List urlTypes) or use the static setDefaultURLTypes(final List urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
at org.reflections.vfs.Vfs.fromURL(Vfs.java:109)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
at org.reflections.Reflections.scan(Reflections.java:237)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.(Reflections.java:129)
at com.thoughtworks.gauge.scan.ClasspathScanner.createReflections(ClasspathScanner.java:60)
at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:37)
at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:36)
09:17:26.687 [INFO] java.net.SocketException: Connection reset
09:17:26.687 [INFO] at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
09:17:26.687 [INFO] at com.google.protobuf.CodedInputStream.tryRefillBuffer(CodedInputStream.java:1121)
09:17:26.687 [INFO] at com.google.protobuf.CodedInputStream.refillBuffer(CodedInputStream.java:1081)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.google.protobuf.CodedInputStream.readRawByte(CodedInputStream.java:1149)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.google.protobuf.CodedInputStream.readRawVarint64SlowPath(CodedInputStream.java:778)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.google.protobuf.CodedInputStream.readRawVarint64(CodedInputStream.java:770)
09:17:26.687 [INFO] at com.thoughtworks.gauge.connection.GaugeConnection.getMessageLength(GaugeConnection.java:51)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.thoughtworks.gauge.connection.GaugeConnection.getAPIResponse(GaugeConnection.java:150)
09:17:26.687 [INFO] at com.thoughtworks.gauge.connection.GaugeConnection.getStepValue(GaugeConnection.java:190)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.thoughtworks.gauge.connection.GaugeConnection.getStepValue(GaugeConnection.java:176)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.thoughtworks.gauge.scan.StepsScanner.buildStepRegistry(StepsScanner.java:47)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.thoughtworks.gauge.scan.StepsScanner.scan(StepsScanner.java:39)
09:17:26.687 [INFO]
09:17:26.687 [INFO] at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:39)
09:17:26.687 [INFO] at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:36)
09:17:26.687 [INFO]
09:17:26.688 [INFO] Exception in thread "main" java.lang.NullPointerException
09:17:26.688 [INFO] at com.thoughtworks.gauge.registry.StepRegistry.addStepImplementation(StepRegistry.java:29)
09:17:26.688 [INFO] at com.thoughtworks.gauge.scan.StepsScanner.buildStepRegistry(StepsScanner.java:48)
09:17:26.688 [INFO] at com.thoughtworks.gauge.scan.StepsScanner.scan(StepsScanner.java:39)
09:17:26.688 [INFO] at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:39)
09:17:26.688 [INFO]
09:17:26.688 [INFO] at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:36)
Javadoc for Gauge Java classes (Table, TableRow, BeforeStep, etc.) should be published on the web for all to see. While Gauge Java is not fully documented at this point, posting it online will encourage open source commits to improve it, and also make it easier to use.
A method can be marked with the annotation @beforeClassSteps
or @afterClassSteps
in any class to execute before or after every gauge step defined in the class.
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:307 +0x59
[exec] path/filepath.Walk(0xc08205ac60, 0x22, 0xc082063b28, 0x0, 0x0)
[exec] /usr/local/Cellar/go/1.4.2/libexec/src/path/filepath/path.go:392 +0xbd
[exec] main.getExecPathFrom(0x709130, 0x9, 0x7128b0, 0xf, 0xc08200ccd0, 0x9, 0x0, 0x0)
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:311 +0x10e
[exec] main.build(0x712890, 0x9, 0xc082082000, 0xbc)
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:365 +0xa41
[exec] main.createClasspath(0x0, 0x0)
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:291 +0x2a6
[exec] main.startJava()
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:81 +0x6b
[exec] main.main()
[exec] /Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:61 +0x3b
Currently it compiles all the files under src
. This might be alright for 90% of the projects. But if they are using gauge together with the application code, then there will too many files which needs to be compiled unnecessarily. So have a configuration in .properties file which will say the directory to be compiled. So only tests
directory can be specified.
It was compiling only src/test/java
directory. But it was removed by the commit getgauge/gauge@9d38589. See the commit message for more information.
318 [main] WARN org.reflections.Reflections - could not create Dir using directory from url file:/Users/prateekb/.gauge/plugins/java/0.0.5/*. skipping.
java.lang.RuntimeException: cannot use dir null
at org.reflections.vfs.SystemDir.(SystemDir.java:20)
at org.reflections.vfs.Vfs$DefaultUrlTypes$3.createDir(Vfs.java:237)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:99)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:91)
at org.reflections.Reflections.scan(Reflections.java:231)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.(Reflections.java:129)
at com.thoughtworks.gauge.GaugeRuntime.scanForStepImplementations(GaugeRuntime.java:158)
at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:139)
Eg.: for step
* A step
@Step("A step")
public void contextStep() {
// some comment
}
On Refactoring
gauge --refactor "A step" "Changed step"
The method changes:
@Step("Changed step")
public void contextStep() {
}
The comment is removed.
This is needed if the project is being built by tools like ant, maven etc. The dependencies can be located at places other than libs directory (like maven local repository).
classpath can be passed as an environment variable gauge_custom_classpath
With the following spec and implementation, on renaming the parameter name one encounters compilation issue
Specification:
Users should be able to start the game
======================================
* Refactor "me" the parameter name
User should be able to access the site
--------------------------------------
tags: join
Implementation:
@Step("Refactor <me> the parameter name")
public void RefactorTheParameterName(String me) {
driver.get("https://www.thoughtworks.com/");
assertEquals(me, false);
};
Hi!
Would be great if Gauge will provide an integration with IoC frameworks, it found it very useful in Cucumber-JVM and miss it in Gauge.
Motivation - sharing dependencies between step implementations without singletons and ugly hacks. In case of Guice - having different scopes ( Scenario, Suite )
On implementing the step
a should be equal to "a"
in the code the implementation is @Step("a should be equal to <a>")
Users should be able to start the game
======================================
User should be able to access the site
--------------------------------------
tags: join
User should be able to join an existing game
--------------------------------------------
tags: search
* a should be equal to "a"
Currently, we are only uploading gauge-java-nightly plugin in bintray, but gauge-java-nightly package is not uploaded for maven projects, so there is no way for maven users to use nightly package.
When a message is written using Gauge.writeMessage, it is expected to see the message displayed in the report, inside the step/spec where the call was done.
The message is completely ignored in the report.
Spec:
Testing Specification
=====================
Specification for testing purposes
Testing Scenario
----------------
tags: writeMessage
* Hello World
* Fail unconditionally
Steps
import com.thoughtworks.gauge.Gauge;
import com.thoughtworks.gauge.Step;
import org.junit.Assert;
public class MockingSteps {
@Step("Hello World")
public void helloWorld() {
Assert.assertTrue("Hello World!", true);
}
@Step("Fail unconditionally")
public void fail() {
Gauge.writeMessage("I'm going to fail");
Assert.assertTrue("Fail unconditionally", false);
}
}
Execution using Maven:
gauge:execute -DspecsDir=specs -Denv="qa" -Dtags="writeMessage"
Gauge version: 0.3.2
Plugins
-------
html-report (2.0.0)
java (0.3.4)
xml-report (0.1.2)
Runner start fails because plugin tries to compile all files under src directory.
Ideally it should still start in case all the step implementations are located in jars as dependencies.
My machine had the latest gauge-java (0.3.3) but the code I pulled had the pom dependency on gauge-java 0.2.2.
While executing the tests, the error on the console was as follows. It was impossible to understand the issue was because of the version mismatch. We should have a proper error message for the same.
[INFO] --- gauge-maven-plugin:1.0.2:execute (default) @ FunctionalTests ---
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x46fd82]
goroutine 1 [running]:
github.com/getgauge/gauge/execution.(*specValidator).validateStep(0xc0821769c0
0xc0820608c0, 0xc082054b10)
/tmp/src/github.com/getgauge/gauge/execution/validator.go:117 +0x3d2
github.com/getgauge/gauge/execution.(*specValidator).Step(0xc0821769c0, 0xc082
08c0)
/tmp/src/github.com/getgauge/gauge/execution/validator.go:93 +0x121
github.com/getgauge/gauge/parser.(*Scenario).Traverse(0xc08206c0c0, 0x259038,
c0821769c0)
/tmp/src/github.com/getgauge/gauge/parser/specificationTraverser.go:70
0x1c4
github.com/getgauge/gauge/parser.(*Specification).Traverse(0xc082019960, 0x258
8, 0xc0821769c0)
/tmp/src/github.com/getgauge/gauge/parser/specificationTraverser.go:45
0x1d3
github.com/getgauge/gauge/execution.(*specValidator).validate(0xc0821769c0, 0x
0x0, 0x0)
/tmp/src/github.com/getgauge/gauge/execution/validator.go:81 +0x7e
github.com/getgauge/gauge/execution.(*validator).validate(0xc08206e720, 0xc082
4f80)
/tmp/src/github.com/getgauge/gauge/execution/validator.go:68 +0x1b4
github.com/getgauge/gauge/execution.validateSpecs(0xc0820c9680, 0xc082014160,
15, 0x15, 0xc08207f2a0, 0xc082004f80, 0xc082004f80)
/tmp/src/github.com/getgauge/gauge/execution/execute.go:89 +0x14f
github.com/getgauge/gauge/execution.ExecuteSpecs(0xc082004500, 0xc0820045f0, 0
, 0x1)
From @kdabir,
A way to access table elements as table["row name"]["col name"]
will be easy to use.
This would also make it easy to use with idiomatic way of writing in Groovy.
Step :
In an empty directory initialize a project with the current language
method :
@Step({"In an empty directory initialize a project with the current language"})
public void initializeProject() throws Exception {
}
Gauge-java is not handling the case where array with 1 step text ({"In an empty directory initialize a project with the current language"}
) is passed to @Step
annotation.
I like the format of gauge specification.
But when I try to implement my step using Geb. I found that Gauge Java try to do everything by it self. From source code compiling to spec executing...
Gauge provides Gralde and Maven plugins. However, they all looks like gauge executable invokers. And will not use all existing and de-facto build process. Reflections works on class files, but I just cannot use the Step implementation compiled by Gradle / Maven, because of my source code is not ending with .java? 😯
Rename gauge-java
to gauge-jvm
just like https://github.com/cucumber/cucumber-jvm maybe a good start?
When multiple jvm args are passed in the java.properties file (eg.- gauge_jvm_args = -Xmx1024m -Xms128m) the jvm does not launch. Only single args can be passed currently. This occurs because the java launcher adds the entire property to the arguments while launching the java runner instead each of the argument should be passed separately.
Need to move this property to take a comma separated value just like the other properties in the java.properties file. eg. gauge_jvm_args = -Xmx1024m, -Xms128m
If there is more than one @BeforeScenario
hook, they are executed in random order. They could be executed in order as :
If there is more than one hook in any of the above category, hooks will be sorted based on method names and executed in that order.
When gauge tries to build the java project, if the src directory is not present or any of the directories mentioned under gauge_custom_compile_directory property then the below exception is thrown.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xa code=0x2 addr=0x14 pc=0x5bec]
goroutine 1 [running]:
main.func·004(0x235450, 0x3, 0x0, 0x0, 0x511e98, 0x11136980, 0x0, 0x0)
/Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:378 +0x16c
path/filepath.Walk(0x235450, 0x3, 0x1115ae84, 0x0, 0x0)
/usr/local/Cellar/go/1.4.2/libexec/src/path/filepath/path.go:392 +0x91
main.build(0x243938, 0x9, 0x1112e620, 0x6b)
/Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:387 +0x53a
main.createClasspath(0x0, 0x0)
/Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:327 +0x25d
main.startJava()
/Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:81 +0x53
main.main()
/Applications/Go Agent.app/pipelines/Gauge-Java/tmp/src/gauge-java/gauge-java.go:61 +0x30
A more meaningful error message should be displayed instead.
Refer getgauge/gauge-csharp#55
To string of the Table parameter should give all the contents of the table
To string of the Table parameter is the default implementation
Something
=========
wwwwwwww
--------
* Verify email text is <table:/email.csv>
Id,Name
1,The Way to Go On
2,Ivo Jay Balbaert
@Step("Verify email text is <table:/email.csv>")
public void implementation7(Object arg0) {
System.out.println(arg0.toString());
}
Gauge version: 0.4.1.nightly-2016-04-19
Plugins
-------
html-report (2.1.0)
java (0.3.4.nightly-2016-04-19)
These custom messages will be added to the HTML Report.
From @sguptatw on April 1, 2016 4:8
With the spec
Users should be able to start the game
======================================
* User "\n"should be able to join the game
User should be able to access the site
--------------------------------------
tags: join
the implementation being
@Step("User <user>should be able to join the game")
public void UserShouldBeAbleToJoinTheGame(Object arg1) {
driver.get("https://www.thoughtworks.com/");
assertEquals(arg1, "\n");
}
refactor the name of the step to something else
now the code is having error with
@Step("User <user>should be able to join the game")
public void UserShouldBeAbleToJoinTheGame(Object arg1) {
driver.get("https://www.thoughtworks.com/");
assertEquals(arg1, "
");
}
Copied from original issue: getgauge/gauge#315
Eg: Refactoring a step Step with Û character
fails
Particularly, note down methods that are for "internal gauge api use only".
Project created using gauge --init java
has a deprecated method table.getRows()
We should only package v0.9.10 of reflections jar.
Reported by @jeremy-flusin on getgauge/gauge#230
From @sguptatw on May 10, 2016 9:51
Create a one.csv
code,status
u1,active
u2,inactive
u3, active
Create a spec with a step
spec
===
scenario
----------
* steppass "1"
* steppass <table:one.csv>
How should the step implementation look like?
Inconvertable types
.Create oneMore.csv
...Somelong text
* steppass "1"
* steppass "a"
* steppass "!"
* steppass <file:specs/one.csv>
* steppass <file:specs/oneMore.csv>
@Step("steppass <arg0>")
public void implementation2(Object arg0) {
System.out.println("table content : " +((Table)arg0).getColumnNames());
}
Error Message: java.lang.IllegalArgumentException: argument type mismatch
Stacktrace:
Copied from original issue: getgauge/gauge#388
When gauge compiles the project it discards any file without the .java extension under src directories. They are not copied over into the gauge_bin. The files need to be copied over so they are in classpath
If you have two scenarios in your spec that have the same name, you get the following error:
16:53:50.704 [CRIT] [ParseError] <path to spec> : line no: 11, Parse error: Duplicate scenario definitions are not allowed in the same specification
While the line number is sufficient to find the error, it would be even better if the error stated what the duplicate was. For instance, if I had two named "MyScenario", it would say something like:
16:53:50.704 [CRIT] [ParseError] <path to spec> : line no: 11, Parse error: Duplicate scenario definition "MyScenario" found in the same specification
There should be a provision to include external libs via one of the dependency management:
Should add param with param value given to refactor command.
Refactor Vowels in English language are "" "end" "n"
to Vowels in English language are "" "end" "n" "n1"
Expected: String vowelString, String argEnd, String argN, String argVowelstring
Actual: String vowelString, String argEnd, String argN, String argN1
0.4.1
Currently all the implementation class objects are created on step execution (in ClassInstanceManager) and stored till the suite execution ends.
The clearing of these cached objects should be done at different levels that can be configured.
Example:
Refactor the following step
* hello "a"
to
* hello "1"
results in compilation error as refactoring names the param as 1
in implementation.'
The hooks annotation can take tags as parameters and the execution can skip the particular hook based on the tag.
Eg. @BeforeScenario("tag1")
Say one has a table:
Foo | Bar | Baz |
---|---|---|
x | y | z |
a | b | c |
One should then be able to get the values from a row by specifying the column name.
Ex:
<datatype?> row = table.GetRows()[0];
// row["Foo"] should get x
Pick a datatype for Row
that would allow this.
Deprecate row[0]
style index based accessors, since this would be error prone when using large tables.
Currently a fork of the javaParser library is being used for AST parsing while performing refactoring. This was a choice made earlier because of lack of java 8 support.
The javaparser library now comes with 1.8 java support and is actively developed and maintained. We should consider using it instead.
We use IntelliJ with Gauge, and also occasionally run Gauge scenarios from the command line. We have found that the Gauge command line automatically detects the IntelliJ compilation. If IntelliJ is using a different JDK version than the one set in JAVA_HOME (which the command line is using), then you get errors. The only solution we have found is to manually delete the out
directory, which deletes the IntelliJ compilation and allows the command line to compile itself.
We would like to have an option to always compile the Gauge Java files, rather than assuming that whatever compilation already exists is valid.
Before Refactoring :
public class ClassName {@Step("Step having")public void step() {System.out.println("");}}
After Refactoring :
@Step("Step with")
public void step() {
System.out.println("");
}
Refactoring replaced the whole class with the method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.