-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 236, Extended Description argument parsing functionality #283
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked at this in detail, just a quick glance
@@ -27,6 +30,15 @@ public void scenarios_can_have_an_extended_description() { | |||
.and().something(); | |||
} | |||
|
|||
@Test | |||
@As( "Scenario that shows the usage of @At with argument enumeration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/At/As/
return this; | ||
} | ||
|
||
@ExtendedDescription( "We can reference the first argument with $$ or $$1 : $" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was proposed in Isse236, I double escaped the first two occurrences to view the message in the report, but maybe this is misleading
As discussed offline it would be great to also support substitution by parameter name like |
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith( JUnitParamsRunner.class ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically use the DataProviderRunner for parameterized tests
}) | ||
public void scenarios_with_multiple_argument_parameters_can_be_shown_via_click_on_table( boolean bool, int i ) { | ||
given().some_bool_$_and_int_$_value( bool, i ); | ||
// TODO screenshot test & implement frontend "click on table" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this test to the jgiven-tests
project, as the examples project is not meant for 'real' tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a example for future use, so I would propose to let this be and add a test after the feature is implemented.
|
||
function getArgumentList(wordList) { | ||
function isArgument(word) { return !!word.argumentInfo; } | ||
return _.chain(wordList) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please check whether the use of the chain
method has increased the artifact size? There seem to be a problem with that function: https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba#.4s9828vud
var placeHolderCount = 0; | ||
|
||
for(var i = 0; i < string.length; ++i) { | ||
var c = string.charAt(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of aligning code vertically. I typically automatically format my code, so this hand-crafted formatting will be destroyed the next time I touch the file. I guess we need a coding style guide for the JavaScript code :-)
|
||
@RunWith( JUnitParamsRunner.class ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the DataProviderRunner instead
I think I found a general problem. Actually, JGiven does not really implement placeholder variables by name. The current behavior is simply that you can give a placeholder an arbitrary name. But the name is only relevant if it is a number. So if you have something like
and you call the method like argument_names_cannot_be_referenced( 1, 2 ) will result in
while this first sounds wrong, however, the basic idea behind that is that you can give your placeholders arbitrary names. In practice, it also makes nearly never sense to change the order of the arguments. However, I still think that this would be useful feature. The problem now is that changing the behavior could break existing code. For now I suggest that you leave your implementation as it is is, but only document the feature for the @ExtendedDescription annotation and not the @as annotation. |
@@ -2,6 +2,7 @@ | |||
* Utility functions | |||
*/ | |||
|
|||
let _ = require('lodash'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please import 'lodash/core' to reduce the final artifact size. You can also use the ES6 syntax:
import _ from 'lodash/core'
In a next step I suggest to implement the feature for the |
There were some non trivial problems while using webpack with lodash on my side. Based on how I imported the functions, some had a different behaviour and some tests broke.
vs
vs
in The custom import broke almost every function except flow, forEach, curry and filter. The test ran through as if the functions were there, but their behaviour was not as specified (predicates didn't work, Your proposed import solution resulted in a test failure, because of the I'm trying to get onto why the custom import of functions does not behave the way it should. And for the new @as functionality, I'm on board with implementing the references by argument names. |
Something is kind of strange in the util.js, because the function I've also stumbled upon the old code in jgiven-html5-report |
I have now a working test where both imported functions from lodash (one with _, and one without) which result in different outputs. The example is the import indexOf from 'lodash/fp';
import _ from 'lodash';
function parseNextArgumentName(string) {
var stopChars = [" ", ",", ";", ":","\"","%","!","[","]","(",")","-","_"];
var isNonStopChar = function (c) {
console.log("char: " + c + ", _.ix: " + _.indexOf(stopChars, c)
+ ", ix: " + indexOf(stopChars, c));
return indexOf(stopChars, c) === -1;
};
var res = _.takeWhile(string, isNonStopChar).join("");
return res;
} The call to
The manually imported |
The point is that you import from the 'fp' module of lodash. The functions of this module are different. I would suggest to not use this for now to avoid these kinds of problems. |
Regarding
I have removed them on master now. |
There is another minor issue regarding consistency between the |
I fixed the imports now, this is still a very strange behaviour of the Edit: Currently working on the real test to check the html for the valid extended description. |
I think I found another error, since the merge to the new jgiven-html-app the tests in HtmlReport don't work anymore. I tested it on my issue branch and the branch where the new html-app was introduced. The problem seems to be this, and with my little knowledge of angular it might be that this call to jgivenReportApp.filter('encodeUri', function ($window) {
return $window.encodeURIComponent;
}) in reportApp.js is the culprit. With the previous minor version of The error is thrown here in the findTagWithName method. After changing This may be still the problem of angular. Edit: Interestingly enough, an Edit 2: This problem resolved itself after updating to the current master branch. Added the current sometimes working version. |
- added front-end tests in utilTest.js - added example usage in ExtendedDescriptionTest.java - added example for @as usage with direct references to arguments in AsAnnotationExampleTest.java - added documentation for @as and @ExtendedDescription in step-usage missing: - tests for extended description in html5report
fixed typo
* added js unit tests * modified docs to show named arguments
Looks like this is only a problem on my ubuntu box:
The mac, as well as travis don't seem to have any issues. |
Ok. Then ignore the issues on your machine for now :-) |
function from util.js
|
||
given().a_report_model() | ||
.and().step_$_of_scenario_$_has_extended_description_with_arguments( 1, 1, description, argumentMap ); | ||
jsonReports | ||
.and().the_report_exist_as_JSON_file(); | ||
whenReport.when().the_HTML_Report_Generator_is_executed(); | ||
when().the_page_of_scenario_$_is_opened( 1 ); | ||
when().the_page_of_scenario_$_is_opened( 1 ) | ||
.and().show_angular_foundation_tooltip_with_$_ms_delay_for_element_$_with_attribute_$_and_value_$(251, "span", "class", "has-tip" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should introduce another step here that hides the internal details of the implementation. Always think from the perspective of a non-technical person, when writing the scenarios.
For example: the_tooltip_of_extended_description_is_shown()
. That method can then call your internal implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of it as the person looking at the test, and if it didn't work because of the newly introduced framework that doesn't use angular-tooltips, I would want to know this dependency explicitly.
WebElement webElement = webDriver.findElements( By.xpath( "//" + element + "[@"+ attribute +"='" + value + "']" )).get( 0 ); | ||
builder.moveToElement( webElement ).clickAndHold().build().perform(); | ||
WebDriverWait wait = new WebDriverWait( webDriver, ms ); | ||
wait.until( ExpectedConditions.presenceOfElementLocated( By.xpath( "//span[@is-open]" ))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that is nice!
missing: