Can I write "or" statements in Cucumber? - cucumber

I am new to using the Cucumber testing framework and am trying to test if a table contains a value in one of the cells. The value I am looking for can vary between 4 different values: Pending, Idle, Active, Unknown. How can I test to see if at least one of these values exist?
This is what I have currently but it only tests for one of the values:
Scenario: Status exists in my table
When I am in the Edge UI
And I click "Administration"
And I click "Sites"
Then I see "Site Elements"
And I see "Idle" inside table
This is what I want to be able to do:
Scenario: Status exists in my table
When I am in the Edge UI
And I click "Administration"
And I click "Sites"
Then I see "Site Elements"
And I see "Idle" or "Pending" or "Active" or "Unknown" inside table

You can make regex pattern in last row like this:
And I see (.*)
After that in method you can use ifs ose switch
Switch(parameter)
{
Case: "Idle":
// logic here
}

Yes, cucumber expressions give you the flexibility to use or's via /.
See https://cucumber.io/docs/cucumber/cucumber-expressions/#alternative-text for more information.

You should write your Cukes in a different way. Instead of using your cukes to document HOW you do something you should use them to document WHAT you are doing and WHY its important. This involves pushing all the HOW into step definitions or better yet helper methods called by step definitions.
The second thing you want a scenario to do is too actually test some behaviour. So ideally you want to do something that changes one of these states, i.e. you perfom an action that results in the value from pending to active.
All this stuff about clicking this and clicking that and seeing particular strings is a really good way to write really fragile scenarios which break whenever someone changes minor details in HOW something is done even if those changes don't break the functionality of what is being done

Scenario: Any status exists in my table
When I am in the Edge UI
And I click "Administration"
And I click "Sites"
Then I see "Site Elements"
And I see a site status inside the table
I believe this is what you are trying to communicate here. Inside your step definition, you can then check that it is one of the recognised statuses.
Given('I see a site status inside the table', function (){...})
However, if you're trying to locate each individual one, then splitting this into a Scenario Outline, and using some of the other answers here as inspiration, you can match the status that you are meant to see in each scenario:
defineParameterType(new ParameterType(
'siteStatus',
/Idle|Pending|Active|Unknown/,
String,
s => new String(s)
))
Given('I see "{siteStatus}" inside the table', function (){...})
OR
Given(/^I see "(Idle|Pending|Active|Unknown) inside the table"$/, function (){...})
Alongside
Scenario Template: Each status exists in my table
When I am in the Edge UI
And I click "Administration"
And I click "Sites"
Then I see "Site Elements"
And I see a "<status>" inside the table
Scenarios:
| status |
| Idle |
| Pending |
| Active |
| Unknown |

Related

How to perform Looping Through List Items in SharePoint 2013 Designer Workflows?

I am new to SharePoint. I'm creating a workflow in SharePoint 2013 in which I want to iterate a List using a loop.
How to perform looping through list items in SharePoint 2013 Designer Workflows?
I'm not aware that there's any out-of-box way to get a workflow to "loop through" all entries in a list, but you can try to make two workflows bouncing back to each other until all entries are updated, here is the detailed steps,
assuming that the list that we are working on is named list_work, in this list, create a column named e.g. cargo
define another list, name it e.g. list_control,
define a column named e.g. listID,
define a column named e.g. cargo,
create one entry in the list, set the cargo to a value.
define a workflow, name it e.g. workflow_list_control, which is triggered every time the entry in list_control is updated, and in this workflow,
search for an entry in the list_work where the list_work.cargo doesn't equal list_control.cargo
if any entry is found, update the entry of list_work and set the list_work.cargo with list_control.cargo, in order to trigger the workflow_list_work (see #4 below)
if no entry is found, stop this workflow.
define the workflow that needs to be run on the list_work, e.g. named workflow_list_work, make it's triggered every time the entry in list_work is updated, and in this workflow, make sure it updates the only entry in the list_control with the ID of the entry from list_work that is being modified, only to trigger the workflow_list_control. In this step, try to put a workflow step to wait and verify the ID is properly updated, in order to allow enough time for the previous workflow_list_control properly finishes.
Every time if a looping-through is necessary, modify the entry in list_control with a different value in the cargo field.
Also refer to calculated-column-to-retrieve-total-number-of-id
You can do this in SharePoint 2013 (ONLY!) using the new "HTTP web service". The "trick" is to
Create a task that will call the HTTP Web Service and call ".../client.svc/web/lists/getbyid(<List Guid>)/items"
Return the (JSON) results in a (new in 2013 also!) "dictionary" variable
Use the "Get an Item from a Dictionary" action
"item by name or path" and enter "d/results"
select the "dictionary" variable (that you captured the results in)
output to another dictionary variable (call it "data")
Then get the count (for the loop) by using the action "Count Items in data" and output that to a variable (totalItems) to get the number of records
For the "loop" you will use the "Loop with condition"; use a variable called "index" and set it to 0. "Loop with condition" until "index < totalItems"
In the body of the loop:
"Get an item from a dictionary" use "item by name or path"
using string builder "d/results/(<index>)/".
The "Column Name to Retrieve" will be whatever column(s) you want to evaluate (like maybe "DueDate").
Note: You will have to use the "Static Name" of the column, which can be found by going to the Task List Settings and clicking the name of the column, then in the URL find the "Field=<Name>" portion.. It is that "<Name>" that you will use.
I know this is very CRUDE maybe even bordering on "useless" for alot of users, but I felt I should at least attempt a quick reply. When I have more time, I will try to edit this and format my reply better. Although, I found this because of a similar need and since I figured out a way to accomplish what I was needing, I felt compelled to at least share it the best I could, in the limited time I had available. ;) So, maybe SOMEONE will find what I have attempted to describe, "useful". :)

Same Step Definitions in Cucumber Gherkins

I have the following Gherkins:
Given i go to the URL
And i enter the <NRIC or FIN> as NRIC / FIN
And i select the option to proceed Next
And i select the first available available Handset Color
And i select the option to proceed Next
And i enter <Full Name> as Name
When i select the option to proceed Next
The "I select the option to proceed Next" appears three times. How should this be written as in the Step Definitions Java class file?
As well as the Declarative/Imperative question have a think about what requirement you're describing. I find it's helpful to include the Scenario: in the examples for this reason. It's very unusual to have that much detail in a Given step
Are you testing the creation of an order (bit of a guess)? If so then your enter/select steps should be the Whens in the scenario, so something like:
Scenario: Create a new order
Given I have gone to the URL
When I enter the NRIC/FIN: <NRIC/FIN>
And I choose the first available Handset Colour
And I enter <Full Name> as Name
Then my new order should be confirmed (or whatever)
However, if you're creating the order simply to set up the scenario to test something else then you can cheat and just state that the order should exist:
Scenario: Check the status of an order
Given that I have created an order:
| NRIC/FIN | Colour | Full Name |
| xxxxx | Red | John Doe |
When I check the status of my order
Then I should see a new order...
It's up to the automation whether it clicks through the screens to create that order or just inserts it into the database, all that matters is that by the time you get to the Whens the order should exist.
In an ideal BDD world the Gherkin would be written before the implementation, but it often doesn't work that way. I still find it useful to try and pretend I'm writing the Features in that ideal world. Asking "How would I have written this before we started development?" can help to separate the actual requirements (I can enter an order) from implementation details (I click Next after entering each item of data).
When writing cucumber scenarios you can adopt either a imperative or declarative style. I would prefer to write the same thing as below.
Given i go to the URL
And i enter NRIC / FIN
And i select the first available Handset Color
And i enter <Full Name> as Name
Then I should see that
So it depends on who is going to read your scenarios. A link worth reading is imperative - declarative

How to write declarative Cucumber features for describing CRUD operations?

I understand the difference between imperative and declarative cucumber steps, but I have not seen any real world examples of this. I always feel like my feature files are becoming too verbose.
It seems like there would need to be a cucumber feature for each step in the life cycle:
foobars/list_foobars.feature
foobars/create_foobar.feature
foobars/view_foobar.feature
foobars/edit_foobar.feature
foobars/delete_foobar.feature
In the create feature alone, it seems like you would want to list out the fields that can be entered, which ones are required, what happens when you enter invalid data, etc. I don't know of a declarative way to do this. Of course in subsequent features, you would just say Given a foobar exists rather than going through all the steps to create one.
How detailed do you go when describing your application's behavior? Can you provide some examples of feature files that you feel are acceptably complete?
I like to keep cucumber tests human readable, so assuming we have a story for editing a foobar with invalid data, I'd want a scenario like:
# foobars/edit_foobar.feature
Feature: As a user, I want to edit a Foobar, so I can Baz
Scenario: Validation Errors
Given I am logged in as a user
And a foobar exists
And I edit the foobar with invalid data
Then I should see validation errors
I think that captures what we want out of the story, without having to deal with all the details of which fields to edit, what buttons to submit, etc. It doesn't test all the possible cases, but those should really be tested via unit tests (model tests that the validations are set, and controller tests that the flash messages are set or request tests that the errors are being served).
The other scenarios are similar:
Scenario: Successful Edit
Given I am logged in as a user
And a foobar exists
And I edit the foobar with valid data
Then I should see the valid data
Some people will want to specify the valid data as part of the test itself, but I personally prefer to delegate these to the step definitions in order to keep the scenarios clean. You just need one example to make sure the golden case works, because again this isn't the appropriate place to test that all the form fields work (and it will become a maintenance headache if you do specify every single field).
I am thinking maybe not test this at all using Cucumber, instead just make a comment in the Feature section.
Alternatively maybe one can do something like this:
# categories.feature
Scenario: Manage categories
Given I want to manage categories
When I <crud_type> a category
Then I should be taken to the listing page
Examples:
| crud_type |
| create |
| edit |
| delete |
Scenario: View category
Given I want to view a particular category
When I click on a category in the category list
Then I should see that category's view page

How should I implement `OnLoad` event handler when creating an activity using a contact?

I've created my own solution with a custom entity of type activity. I'd like to show a message whenever a new instance of it is created using an existing contact but not allow the user to create one, if only attempting to do that without going via contact.
Basically, my aim is that it won't be impossible to just create that activity (the form will be hidden directly at any attempt except for one way only). The user will have to go to contacts (or leads etc.) and in there add and create an instance of the custom activity entity. That way, I can assure that the field "regarding" will be filled out already.
I'm guessing that I need to detect somehow that the opening of the form is a creation attempt. How can I do that?
Also, as it is now, the user can't create a contact-less activity of the custom type because it doesn't appear on the menu with other activities. I must have disabled it somehow but I have no idea how. Anybody who has one?
You could do this a bunch of ways but the easiest would probably be to:
Make the regarding field read only.
Make the regarding field mandatory.
That way if a user opens a create new form they wont be able to set the regarding and because its mandatory they wont be able to save the record. When they open via an existing contact the regarding field will be mapped automatically. That said in this case just making it mandatory my be enough.
(As a side JavaScript can be used to identify the current form state, but I'm not sure how useful that is here).
In terms of where custom activities appear, by default mine show in a number of locations, for example:
CRM > Workplace > Activities > Ribbon > Other Activities > XXX.
CRM > Workplace > Activities > View Selector > XXX.
They don't show under the left hand navigation of the workplace because they are grouped under 'Activities'. I'm pretty sure these are all the default settings.
You can exercise greater control by editing the sitemap, where you can put pretty much anything, anywhere.
In addition to Mr Wood, I'd like to show you some code. It works as supposed to but I'm not sure if it's optimal.
var foo = function () {
var whatIsGoingOn = Xrm.Page.ui.getFormType();
if (whatIsGoingOn === 1)
alert("Let there be an entity!");
else
alert("Not a creation...");
}
The other states' (deletion, update etc.) numeric values are listed here.
Answering the second part of your question:
When you create a custom activity you can choose whether to have it appear in 'normal' Activity menus or not by checking the box at the top right of the entity form. This is a once-only choice as far as I know and can't be changed later.
For your setup, I would suggest NOT checking this box, so it does not appear in the activity menus to avoid users even being tempted to do it that way.
Instead, add an explicit relationship to the activity N:1 to Contact, and another N:1 to Lead. Use this relationship to add your activity to the left navigation of Contact and Lead forms, or add a grid for them (depends on how you want to use this and if you need to filter the view to something other than the default "Associated View").
When a user navigates to this section they will see if any previous activities of this type exist, and be able to add a new one. BUT this means that the child record is a child via this relationship, not using "regarding", so use a script on the form for the activity so that if Contact is filled in, it is copied to Regarding, and if Lead is filled in then that is copied. If neither, then use an alert or other means to warn the use that something is wrong (see comment earlier). If you want Regarding to be read-only but filled in by script, you will need to make sure to use the force the value to be saved:
Xrm.Page.getAttribute("regardingobjectid").setSubmitMode("always");
You must have the lookups for Contact and Lead on the form to be able to use them in your scripts, but you can make them not "visible by default" so they are there but not seen by the user (and taking up no space).

Can "Excel Add-In for Coded UI Testing" help when reading test scenario data from Excel worksheet

This requires a detailed explanation.
Imagine that I have an Excel spreadsheet with test cases in one worksheet
and I may have expected (validation) messages in another (in addition to expected messages in the first worksheet).
There is also some linking between the values of fields in one to the second worksheets.
See: Welcome, <First Name> <Last Name> as an example.
You can see in the "Expected Results" field in "Test cases" worksheet the value of the field is:
"The user is taken to My Account page and following welcome message is displayed:
"&Messages!$B$1244&", where First name is Dave and Last Name is Brown."
so "&Messages!$B$1244&", denotes field B1244 in worksheet "Messages"
Now the question.
If I am given all test cases like the example below for an ecommerce web site, how can I use Coded UI Testing based on this input? Can I automate Excel, use the steps in test case worksheet and combine that with Coded UI recording of data input and verification.
I believe I would need to do manual coding, partially using recorded input steps and verifications from Coded UI recorder and possibly using manual programming for verification.
I would like to hear if others have done something similar.
I would like to incorporate this into Specflow BDD, by writing feature/user story and these test cases will be scenarios.
Any success, thoughts on using Excel test automation as data driven testing.
Thanks
Rad
Test cases worksheet named "Test cases":
=====================
Test Case Name Test Case Objective
frontstore.01-3 Register a shopper from order
confirmation page with valid inputs
# Step Data Expected Results
------------------------------------------------------------------------------------------------
1 Launch the test storefront http://testserver.com/index Welcome page is loaded.
2 Click Sign In link Sign In page is loaded.
3 Click Register under New Customer Register page is loaded.
4 Enter valid inputs and click Submit "Logon ID = TestUser
Firstname = John
Lastname = Clark
... (other fields) Registration Successful.
The user is taken to My Account page
and following welcome message is displayed:
Welcome, <First Name> <Last Name>, where First name is
David and Last Name is Brown."
Validation Messages worksheet named "Messages":
=====================
#Text used in MyAccountPages
---------------------------------------------------------------------------
MA_WELCOME Welcome, <First Name> <Last Name>
After reading a bit about Coded UI testing:
It can certainly be done, but data/sentences like:
“Launch the test storefront”
“Click Sign In link”
“Registration Successful.
The user is taken to My Account page
and following welcome message is displayed:
Welcome, , where First name is
David and Last Name is Brown."
contain both actions and data so I need to drill down into parts of the sentence to
translate it to actions and binding to parameters.
If I understand well data binding can only be used to bind column values to some parameters.
So I need some way to automatically recognize the meaning of these sentences and use some binding
from parts of it.
So if I have a sentence:
“Launch the test storefront” that would be translated to:
CurrentBrowser.Navigate(Helper.TranslateTargetUrlFrom(“test storefront”))
where “test storefront” might resolve to http://testserver.com/index storefront home
page and I can ignore Data column for URL
or I can capture Launch keyword to mean CurrentBrowser.Navigate(ColumnValue(Data)) and ignore “test storefront” part of the sentence.
“Click Sign In link” could be translated to CurrentBrowser.FindLink(“Sign In”).Click(),
so it this case I will need to know that Sign In is
the text of the link, again I need to extract “Sign In” to mean the text of a link.
I see this as pretty manual style of CodedUI where I could do small recording for some actions and rely on manual extractions of terms from
given sentences.
I would like to know how can I semantically write better test cases to allow automation. I would probably need some kind of free form
test case parser that would recognize the semantic meaning of some words like: click, navigate, launch, enter, click under etc and translate this into
code by re-using existing helper methods and recorded actions and do some manual binding, but not with the whole data value in the column, but
an extracted value.
Any idea of this kind of automation?
I think yould could do this by data binding the input parameters and just reading Excel as a datasource, you are going to need to use CodedUI for that not MTM + Fast Forward

Resources