specflow hooks between two given steps - specflow

i have the following specflow test:
#done
#succesfulladdbeforewhen
Scenario Outline: Admin adds an alternate numbers entry with a phonenumber successfully
Given the BW User is logged in with a <userlevel> Level Account
And the AddAlternateNumbersEntry query parameter contains an existing userid within the scope of the BW User
And the AddAlternateNumbersEntry post body contains an available phonenumber
When the BW User submits the AddAlternateNumbersEntry request
Then HTTP 201 should be returned
And a new alternate numbers entry should be added
Examples: User Levels
| userlevel |
| System |
| Service Provider |
| Group |
However i want a hook between before the second "and" (And the AddAlternateNumbersEntry post body contains an available phonenumber)
How can i do this ??? i can't find the propper kind of code/hook to do it with. thnx for the advice
thnx

Related

Mosquitto >1.5 User Access Level Wildcard

I am trying to use Mosquitto MQTT Broker v1.5.8.
I am using mosquitto_auth_plugin for User Authentication. (https://github.com/jpmens/mosquitto-auth-plug)
I created a mysql server with users and acls tables.
I want to setup a user that can subscribe to topic test/#.
So I setup the rw = 5 in the acls table for that user
However the user is not able to subscribe to any test/# but can subscribe to test/123
I looked at one of the issue posted https://github.com/jpmens/mosquitto-auth-plug/issues/356
but since the Repo is archived, I cant ask questions there.
mysql> select * from acls;
+----+--------------+--------------------+----+
| id | username | topic | rw |
+----+--------------+--------------------+----+
| 1 | test | test/# | 5 |
+----+--------------+--------------------+----+

I want to write script for login functionality. There are 5 types of user for that I have written following feature file

Query: I want to login with different user for that I am parametrizing the Usertype and will verify the respective element w.r.t there access.
Now In Step file suppose eg: I have written
#Then ("^User logged in with \"([^\"]*)\"$)
Public void User_logged_in_with_Usertype() {
If (Usertype= Admin){
...
So in above code in how I will get value of admin or any other user(Can we get same value from feature file or I need to write a code separately for each user)
Feature: As a user I would like to login in FMJ-Redesign application with different users
Story : User is logging in FMJ application
Scenario Outline: User is logged in with Admin user credentials
Given Navigating BU to "<Browser>"
When User clicks on Location
And ForevermarkJewellerWebsite element should be present on login page
Then User logged in with "<Usertype>"
And User will check visibility of "<Element>"
Then User Logout Successfully
Examples:
|Browser | UserType | Element |
|Chrome | Admin | |
|Chrome | Market | |
|Chrome | Jeweller | |
|Chrome | Store | |
The way to get the value for Usertype is to have it as a parameter in the method.
Your code looks like this:
#Then ("^User logged in with \"([^\"]*)\"$)
Public void User_logged_in_with_Usertype() {
If (Usertype= Admin){
...
I rewrote your Scenario outline a bit and ended up with this version
Scenario Outline: User is logged in with Admin user credentials
Given Navigating BU to <Browser>
When User clicks on Location
And ForevermarkJewellerWebsite element should be present on login page
Then User logged in with <UserType>
And User will check visibility of <Element>
Then User Logout Successfully
Examples:
| Browser | UserType | Element |
| Chrome | Admin | |
| Chrome | Market | |
| Chrome | Jeweller | |
| Chrome | Store | |
This allowed me to write the step like this:
#Then("^User logged in with (.*)$")
public void user_logged_in_with(String userType) throws Throwable {
if (userType.equals("Admin")) {
// implement our behaviour here
}
}
There are a few differences to notice here:
I removed the quotes around the parameters in the example
I added the value of UsertType as a parameter to the method user_logged_in_with
These changes simplified the regular expression needed and allows you to implement different behaviour for different UserTypes.
I would probably implement four different steps for the user types you have. This would give me simpler steps, I could avoid the condition. The price would be four methods.
If I did that, the resulting implementation would look like this instead:
#Then("^User logged in with Admin$")
public void user_logged_in_with_Admin() throws Throwable {
// implement our behaviour here
}
This simplified the regular expression even more and removed the need for a capture group.

How map authorizations (and other sub-infos) in oData structure

This is the base schema of oData EDM:
thanks for the image Filippo
I have my db structure:
Product (Code, Description, IVA, Price)
|n
|
|
|
|1
Purchase(ID, Product, Customer)
I want expose my data using oData; I can map in a natural way Product and Purchase in two EntitySet: ProductSet and PurchaseSet.
If I require for example all items of ProductSet I receive a collection of 100 products; each product have 4 properties, for example:
{
Code:01,
Description: "blue pen",
IVA: "19",
Price: "2.99"
}
Ok but based on the user logged, the business logic before oData want send me more information (for example the editable sub property):
{
Code: {value:01, editable:false},
Description: {value:"blue pen", editable:false},
IVA: {value:19, editable:true},
Price: {value:"2.99", editable:true}
}
(I can't sent the new information in this mode, I have only entity sets and properties...)
What is the right way to map editable infos in EDM? A New Property??
You can achieve this by creating a ComplexType that will have the properties of value and editable. So the properties of your Entity will refer to the ComplexType.

How to write a test in cucumber?

This is my first test case with cucumber and I am having tough time to figure out one thing. So I already have a test which check user creation. I want to add more steps like on user create create account and create product and set some attributes to these objects.
Here is the user create feature file
#no-database-cleaner
Feature: Creating an user account
In order to use Recdns portal
I need to create an user account
Scenario: Successful user account creation
Given the database contains no test data
And I am on the homepage
When I attempt to create the following user account:
| email address | password | confirm password |
| abc#company1.com | password | password |
# User is automatically logged in
Then I should see "Welcome!" message on page
And an ar_id is set for the user
And
When I click "Sign Out"
Then I should see "Signed out"
When I attempt to sign in with following user account:
| email address | password |
| abc#company1.com | password |
Then I should see "Welcome!" message on page
Scenario Outline: Verify error message when user failed to sign in
Given there is a user
And I am on the homepage
And I try to login with email "<email address>", password "<password>"
Then I should see "<error message>" message on page
Examples:
| email address | password | error message |
| testuser#company1.com | abc1234 | Invalid email or password |
| testuserdoesnotexist#company1.com | password | Invalid email or password |
Scenario Outline: Verify error message when user failed to sign up
Given I am on the homepage
And I click "Sign Up"
And I try to create user with email "<email address>", password "<password>", confirm password "<confirm password>"
Then I should see "<error message>" message on page
Examples:
| email address | password | confirm password | error message |
| abc#company1.com | abc123 | abc123 | Email has already been taken |
| xyz#test | abc123 | abc123 | Email is invalid |
| | abc123 | abc123 | Email can't be blank |
| abc#company1.com | | abc123 | Password can't be blank |
| abc#company1.com | abc123 | | Password doesn't match confirmation |
| abc#company1.com | abc1 | abc1 | Password is too short |
So where exactly I can add steps saying create account table and product table. Thanks
Is your 'create user account' method something that you need for each test to run? If so, I'd just create a helper that you can call before your scenario. ..something like #needs_new_account. One of the best parts about cucumber is the ability to reuse environments. You probably shouldn't create a new account for each scenario. Instead, have cucumber remember that it needs to keep that new account (ie., dont delete it) and reuse for the rest of your scenarios, if possible. Let me know if this helps. ..not quite sure I'm understanding your question completely.
Also, you don't need your extra "and" between "and" and "when"...Gherkin syntax treats And/When/Then the same.

Specflow not passing table

I've just started playing around with Specflow, Watin and Deleporter.
I am having a problem with an integration type test, in that it wont pass the table data into the corresponding test.
Scenario: User tries to register and their email already exists
Given I have filled out the register page with the following data
| Name | Password | Nickname | Email |
| Sam | password1 | SamsNickname | email#email.com |
When I already have an account with the same email
| Name | Password | Nickname | Email |
| Sam | password1 | SamsNickname | email#email.com |
Then Show message that the account exists
[Given(#"I have filled out the register page with the following data")]
public void GivenIHaveFilledOutTheRegisterPageWithTheFollowingData(Table table)
{
var data = table.Rows.First();
}
The problem I am having is the Table parameter above is passed in as null. Is there something I'm missing here?
The wrong runner executes your test.
Go to the following option:
Tools -> Options -> Specflow -> General -> Test Runner Tool
Change the value to "Auto" or "SpecRun"

Resources