I am trying to write Gherkins with only one variable in a Scenario Outline. I see an error "1 out of bounds for length" when I try running my feature file. However if I add a second variable (another column and another variable) this will pass.
Is there a way to write Scenario Outlines with just one variable instead of two or more? If so, how?
Thank you!
Example A
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see "Yes this is a fruit" message
Examples:
| fruit |
| Kiwi |
| Apple |
| Pineapple |
Gives me an error "1 out of bounds for length"
I can change it to the below format and it passes, but I want to avoid adding an entire column with the same string just to make the Cucumber Gherkins pass.
Example B
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see <message> message
Examples:
| fruit | message
| Kiwi | "Yes this is a fruit"
| Apple | "Yes this is a fruit"
| Pineapple | "Yes this is a fruit"
How can we make Example A valid and pass? Thanks!
This is what works for me with Cucumber 7.4.1:
package so;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class StepDef {
#When("I ask whether {word} is a fruit")
public void i_ask_whether_kiwi_is_a_fruit(String value) {
System.out.println(value);
}
#Then("I should see {string} message")
public void i_should_see_message(String string) {
System.out.println(string);
}
}
Which with this feature file:
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see "Yes this is a fruit" message
Examples:
| fruit |
| Kiwi |
| Apple |
| Pineapple |
gives:
Kiwi
Yes this is a fruit
Apple
Yes this is a fruit
Pineapple
Yes this is a fruit
Related
I have a spreadsheet like so:
| A | B | C |
|------|---|----------------|
| Bob | | Mary is Nice |
| Mary | | Tim is happy |
| Tim | | Bob is awesome |
and I'm trying to use Excel to find the name values in column A and match the content in column C and then match the output in column B like so:
| A | B | C |
|------|----------------|----------------|
| Bob | Bob is awesome | Mary is Nice |
| Mary | Mary is Nice | Tim is happy |
| Tim | Tim is happy | Bob is awesome |
I'm not sure if there is a formula that can find, match, and sort into column B out of the box. Or if I would need to write a macro. I've been looking and the only thing I can find so far is a match based of a specific value and move it into a seperate worksheet.
I can do this with PHP/MySQL, but that's not the intended result, obviously.
Also, maybe something easier to do within Google Sheets instead?
Use INDEX/MATCH with wild cards:
=INDEX(C:C,MATCH("*"&A1&"*",C:C,0))
OR
VLOOKUP:
=VLOOKUP("*"&A1&"*",C:C,1,FALSE)
How to convert rows into string values in Apache Spark
I have a spark dataframe like this:
fruit | name
--------------
fruit | apple
fruit | orange
fruit | mango
I want to convert it into this:
fruit | string
----------------------------
fruit | apple, orange, mango
How can I achieve this in Apache Spark?
Look at collect_list
df.groupBy("fruit").agg(collect_list("name"))
it will group values and create array of them as a new column.
If you want to have string, please see this question (thanks #mtoto)
I'm having troubles creating an Excel formula to repeat the same copy down a column until I come to a new "person". The reason I'm doing this is to Index(Match) later to grab all this data. If I am totally off, and there's an easier way to grab this data than run a formula down 15k rows, I'm all ears. The main problem is that my categorical data (Person) is stacked on top of the data that I want to match it with (Work Positions).
The data looks like this:
Description | Status
Bob | C
Sales |
Marketing |
Management |
John | C
Sales |
Management |
Tony | C
Management |
Ideally, I'd like the data to look like this after running the formula down ColA:
Person | Description | Status
Bob | Bob | C
Bob | Sales |
Bob | Marketing |
Bob | Management |
John | John | C
John | Sales |
John | Management |
Tony | Tony | C
Tony | Management
I've tried writing an If() statement to target the "C" in ColC, as it is always there to discern a change in "Person". However, I can't figure out how to do this as of yet. Is there a way to write a formula that says keep pasting the same value until you hit the next "C", then change your paste value? Thanks for any and all help and please, don't hesitate to ask any clarifying questions!
=IF(C:C="C",B:B,A1)
Put this in A2 and clear "Person" then drag down the list.
We are creating Gherkin feature files for our application to create executable specifications. Currently we have files that look like this:
Given product <type> is found
When the product is clicked
Then detailed information on the product appears
And the field text has a value
And the field price has a value
And the field buy is available
We are wondering if this whole list of and keywords that validate if fields are visible on the screen is the way to go, or if we should shorten that to something like 'validate input'.
We have a similar case in that our service can return a lot of 10's of elements for each case that we could validate. We do not validate every element for each interaction, we only test the elements that are relevant to the test case.
To make it easier to maintain and switch which elements we are using, we use scenario outlines and tables of examples.
Scenario Outline: PO Boxes correctly located
When we search in the USA for "<Input>"
Then the address contains
| Label | Text |
| PO Box | <PoBox> |
| City name | <CityName> |
| State code | <StateCode> |
| ZIP Code | <ZipCode> |
| +4 code | <ZipPlus4> |
Examples:
| ID | Input | PoBox | CityName | StateCode | ZipCode |
| 01 | PO Box 123, 12345 | PO Box 123 | Boston | MA | 12345 |
| 02 | PO Box 321, Whitefish | PO Box 123 | Whitefish | MN | 54321 |
By doing it this way, we have a generic step "the address contains" that uses the 'Label' and 'Text' to test the individual elements. It is a neat and tidy way to test a lot of potential combinations - but it probably depends on your individual use case - how important all of the fields are.
You only need to validate the ones that provide business value, which is probably all of them. I would avoid using tech terms like "field" because it isn't related to a behavior. Al Mills is right on for using the tables.
I'd word it like this:
Scenario Outline: Review product details
Given I find the product <Type>
When I select the product
Then detailed information on the product appears including
| Description | <Description> |
| Price | <Price> |
And I can buy the product
Examples:
| Type | Description | Price |
| Hose | Rubber Hose | 31.99 |
| Sprinkler | Rotating Sprinker | 12.99 |
The words I chose are behaviors or whats, not technical implementations or hows.
I've got a handful of specflow tests that look something like this:
Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email
Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email
Except instead of just 2 scenarios, I've got 10 very similar scenarios, all with the type of steps so I want to use a "Scenario Outline". Unfortunately, I'm having a really hard time coming up with a readable way to re-write my steps.
Currently, I've come up with this but looks clunky:
Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email
Examples:
| !notes | personDoes/NotExist | personShould/NotGetEmail |
| Exists | does not | should |
| No Exist | does | should not |
I also considered this, and while it is cleaner it doesn't convey meaning nearly as well
Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')
Examples:
| !notes | personExist | sendEmail |
| Exists | false | true |
| No Exist | does | false |
Does anybody have a better way of parameterizing concepts like "does", "does not", "should", "should not", "has", "has not"? At this point, I'm thinking about leaving the everything as a different scenario because it is more readable.
Here is what I've done in the past:
Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1 | John | Galt |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following accounts should have been sent an email
| External Id | Email |
| 2 | y |
You can use the table.CreateSet() and table.CreateSet() helper methods in SpecFlow to quickly turn the tables into data for your fake external system repository and your account table in the database.
Then you can use table.CompareToSet(accountRepository.GetAccounts() to compare the table in your "Then" clause to the records in your database.
The neat thing is, all of the steps you wrote are reusable for multiple situations. All you do is change the data in the tables, and SpecFlow writes the tests for you.
Hope that helps!
Maybe you should split them into two scenarios
Scenario Outline: User exists in the repository
Given a person
| Field | Value |
| First | <first> |
| Last | <last> |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email
Examples:
| first | last |
| Bob | Smith |
| Sarah | Jane |
And then another scenario for the opposite. This keeps the scenario meaning very clear. If your common steps are worded genericly you can reuse them. I also try to come from the approach of the user