Do I have to use Given, And, Then, etc... when I am doing a step definition?
For example in my feature file I have Then I login to the app in one scenario. In another scenario I have And I login to the app.
I don't like all the Then And Given 's in step definitions. Is there a way to not have to specifically use these keywords and use some sort of wildcard? I've thought about just using When in step definitions. I just hate mixing all these keywords when they don't really matter anyway.
I wish I could define the step in my step_definition file without having to use various (meaningless) keywords in front of it.
If you want to change this in your feature file, instead of using one of the step definition keywords (Given, When, Then, And, But) you can use an asterisk (*) in your feature file as a sort of bullet point. Example
Scenario: Test Scenario
* run a sample step
* run a different sample step
This will generate
Given(/^run a sample step$/) do
pending # express the regexp above with the code you wish you had
end
Given(/^run a different sample step$/) do
pending # express the regexp above with the code you wish you had
end
Also, Gherkin supports adding languages, this uses a JSON file to define the keywords for the step. This could be used to change what keywords were used for step definitions.
You could fork Gherkin and clone it. Then edit i18n.json to add a new language which uses whatever keywords you wanted instead of these. It currently supports pirate for example. After this you would either have to submit a pull request for them to add the language definition to the project or build Gherkin yourself from the cloned fork (https://github.com/cucumber/gherkin/blob/master/README.md)
Here is the reference page for adding a language
https://github.com/cucumber/cucumber/wiki/Spoken-languages
Related
I want to add pre-steps to Scenario Outline as Scenario, but I don't want to add pre-condition. How can I do that in Jira Xray?
Some illustrative example:
Scenario:
Given: Open website
Then: Check URL
Scenario Outline:
When I click this <button>
Then Something happens with <this> element
I want to have some "background" for Scenario Outline because this is something that repeats in several tests but it turns out that for every step in S.Outline Background is repeating so I want to create a normal Scenario as "artificial" background. How to do that in Xray? Can I add something like pre-step? Pre-condition always creates "Background" in Gherkin.
I don't want to have several Scenario Outline scenarios with a lot of repeated steps.
This is more a Gherkin related question than Xray specific. There are no dependencies between Scenarios in Gherkin.
The way to have some initial Gherkin statements that apply to all to several Scenarios, is by having a Background in the corresponding .feature file.
In Xray this means that you need to have a Precondition, of Cucumber type, with those Gherkin statements. Then you need to associate it all Tests (Scenario/Scenario Outline types) that you want. Whenever exporting those tests, a .feature file will be created with a Background corresponding to the previous Precondition.
The rules for generating .feature files based on Test and Preconditions issues in Xray is detailed here.
Note: in Cucumber libraries there also hooks, that contain code that can be executed before/after tests. However, this is used for something that isn't described as behaviour and more for easing implementation, and doing things like test setup/cleanup.
I've a list of features files and the list of the related step definitions. Every feature file refers to some specific functionality of the website.
According to some environment variables defined in package.json and representing the theme of the website, I might need to skip entirely some of the feature files (and obviously their step definition), due to missing feature for some specific theme.
To give some code examples:
"test:cy:run:daylight": "PORT=9000 CYPRESS_THEME=daylight cypress run",
"test:cy:run:darkness": "PORT=9001 CYPRESS_THEME=darkness cypress run",
feature files list:
daylight.feature
afternoon.feature
evening.feature
night.feature
with the relative definitions:
daylight.spec.js
afternoon.spec.js
evening.spec.js
night.spec.js
So in case of CYPRESS_THEME=darkness I would like to skip entirely from my testing process the features evening.feature and night.feature
How to do that? Ideas?
This example is with fake data, my real scenarios includes many more features and themes, so unluckily splitting test in different folders or using Cypress tag is not an efficient option.
Another not efficient idea I am thinking of is to put conditionals in every step definition Given, When and Then with the help of the detection of the Cypress.env('THEME') but obviously I would prefer not to follow this approach.
Anything else? Thanks
The correct answer would be to tag the tests and run only specific tags... if such a feature existed. I believe #mosaad is wrong on his second point; the --tag command line parameter merely adds meta data to the run from what I understand. It doesn't restrict which spec files get run.
If I were you I'd just try to get creative with your folder structure. Alternatively you can implement this person's workaround, which seems a bit heavy to me but probably gets the job done.
You can split tests into 2 folders and run only the files in this folder
cypress run --spec "cypress/integration/daylight/**/*"
Or you can use tags and run tests with the correct tag
cypress run --record --tag "daylight"
I have a lot of high level test cases.
I have the same keywords implemented for:
CLI (telnet)
WEB
Is there an easy way to run those test cases by not duplicating files, just passing a command line argument or something similar - to run these test cases for both CLI and WEB?
This problem can be solved in different ways and much depends on how you want to structure your test case base and scripts.
Start application. If you have specific resource files for your Web and CLI keywords with the same keyword names for the same checks/processing then remove the unwanted files before you start Robot.
Custom Import Keyword In addition to importing a resource file in the Settings section you can also import a resource file through a keyword: Import Resource. This has the added advantage that you can use variables to create the file reference. For example if you have a global with Web/CLI and seperated the files using a directory, then this can be the folder name reference.
Test Case Tagging By duplicating your test cases you can load all the keywords for CLI and Web. Their keywords should be unique, otherwise they will conflict. By adding Test Case tags you can utilize the tag filter feature when starting Robot to run only those test cases that have and/or lack certain tags.
Given that your test cases are unique test cases in the sense that they test different UI's I'd be enclined to seperate at test case level and use tags. Though there isn't a right or wrong way if you make a conscious decision.
As this closely relates to a solution maintaining settings for different environments, please keep that in mind as well.
I have multiple validations to be done on some web UI. So instead of writing
Then I see "foo" element on the page
And I want the user to see "bar" text
.
.
.
And new order is generated
I want my feature file to be more readable(this might go app-specific and not business specific) and should go something like this
Then following validations are made
* "foo" element is visible
* "bar" text is visible
.
.
.
* new order is generated
My Questions is, '*' keyword has the ability to adapt to any step according to documentation, am I using it correctly? ( I think not because my IDE doesn't think so). What is the correct way of using it?
In other words, how to write steps with * so that IDE understands and recognizes step definition
Let me know if I am not understanding this correctly.
EDIT:
The way I am using '*' is correct, we have to write something like
* "foo" is present
IDE doesn't recognize it may be a problem with the plugin, I wrote the step and the corresponding step definition with any of the standard keywords (Given/When/Then), cucumber recognizes it and works accordingly
The approach I'd use is to find the overall name for all the validations, what are your validations validating?
When you have done that write a single step
Then 'my foo should be valid'
then implement this as something like
Then 'my foo should be valid' do
should_have_valid_bar
should_have_valid_baz
...
end
and then write the helper methods to make this work. This will do the following
Simplify your feature file and make it much easier to read.
Make it much cheaper to add or modify validations.
Transfer responsibility to the programmer.
Simplify your step definitions and reduce their number
In general keep you scnenarios simple and short and don't include detail about HOW things are done. Push that HOW down into step definitions and helper methods.
The GWT should be seen as following:
Given some sort of pre-condition, something kind of setup for the test.
When the action that happens
Then The expected result of the action
the And and But are just representations of the preceding Given, When or Then.
Sometimes, a scenario in this way just is not the best approach (not all jobs need the same tool) and a list of "stuff" is more desirable. i.e.
* Open web browser
* Go to google
* Search for Cheese
* Select a cheese to buy
* go to shop
* buy cheese
* eat cheese
* feel happy
This is where the * should be used to show a list that is a order of instructions. (I'd also be happy to argue that the above could quite easily be written into GWT and that most things can if you understand what you are trying to describe well enough).
I'm relatively new to Expression Engine, and as I'm learning it I am seeing some stuff missing that WordPress has had for a while. A big one for me is shortcodes, since I will use these to allow CMS users to place more complex content in place with their other content.
I'm not seeing any real equivalent to this in EE, apart from a forthcoming plugin that's in private beta.
As an initial test I'm attempting to fake shortcodes by using delimited strings (e.g. #foo#) in the content field, then using a regex to pull those out and pass them to a function that can retrieve the content out of EE's database.
This brings me to a second question, which is that in looking at EE's API docs, there doesn't appear to be a simple means of retrieving the channel entries programmatically (thinking of something akin to WP's built-in get_posts function).
So my questions are:
a) Can this be done?
b) If so, is my method of approaching it reasonable? Or is there something stupidly obvious I'm missing in my approach?
To reiterate, my main objective here is to have some means of allowing people managing content to drop a code in place in their content that will be replaced with channel content.
Thanks for any advice or help you can give me.
Here's a simple example of the functionality you're looking for.
1) Start by installing Low Replace.
2) Create two Global Variables called gv_hello and gv_goodbye with the values "Hello" and "Goodbye" respectively.
3) Put this text into the body of an entry:
[say_hello]
Nice to see you.
[say_goodbye]
4) Put this into your template, wrapping the Low Replace tag around your body field.
{exp:low_replace
find="[say_hello]|[say_goodbye]"
replace="{gv_hello}|{gv_goodbye}"
multiple="yes"
}
{body}
{/exp:low_replace}
5) It should output this into your browser:
Hello
Nice to see you.
Goodbye
Obviously, this is a really simple example. You can put full blown HTML into your global variable. For example, we've used that to render a complex, interactive graphic that isn't editable but can be easily dropped into a page by any editor.
Unfortunately, due to parse order issues, EE tags won't work inside Global Variables. If you need EE tags in your short code output, you'll need to use Low Variables addon instead of Global Variables.
Continued from the comment:
Do you have examples of the kind of shortcodes you want to support/include? Because i have doubts if controlling the page-layout from a text-field or wysiwyg-field is the way to go.
If you want editors to be able to adjust layout or show/hide extra parts on the page, giving them access to some extra fields in the channel, is (imo) much more manageable and future-proof. For instance some selectfields, a relationship (or playa) field, or a matrix, to let them choose which parts to include/exclude on a page, or which entry from another channel to pull content from.
As said in the comment: i totally understand if you want to replace some #foo# tags with images or data from another field (see other answers: nsm-transplant, low_replace). But, giving an editor access to shortcodes and picking them out, is like writing a template-engine to generate ee-template code for the ee-template-engine.
Using some custom fields to let editors pick and choose parts to embed is, i think, much more manageable.
That being said, you could make a plugin to parse the shortcodes from a textareas content, and then program a lot, to fetch data from other modules you want to support. For channel entries you could build out of the channel data library by objectiveHTML. https://github.com/objectivehtml/Channel-Data
I hear you, I too miss shortcodes from WP -- though the reason they work so easily there is the ubiquity of the_content(). With the great flexibility of EE comes fewer blanket solutions.
I'd suggest looking at NSM Transplant. It should fit the bill for you.
There is also a plugin called Shortcode, which you can find here at
Devot-ee
A quote from the page:
Shortcode aims to allow for more dynamic use of content by authors and
editors, allowing for injection of reusable bits of content or even
whole pieces of functionality into any field in EE