what is an alternative way to use instead of id in gherkin? - specflow

I am writing some user stories. I know I can use pesona instead of an Id which is not undrestandable for nontechnical persons. Consider following example:
Given I want to add "Alex" as user with Password "123" and description "blahblahblah"
When I register "Alex"
Then I should see "Alex" in the list of users with password "123 and with description "blahblahblah"
It is understandable but how Can I find "Alex" without a specific Id during acceptance tests?
If I use following scenario, It might not be understandable in one go and also for nontechnical people?
Given I have "Alex" data as following:
| Name | Password | Description |
| Alex | 123 | blahblahblah |
When I register "Alex" as user
Then users must be as following:
| Id | Name | Password | Description |
| 1 | Alex | 123 | blahblahblah |
What is the best way to be used instead of Id to be understandable for nontechnical and also be testable?

Consider the following, which may be a little more effective, though more verbose.
Given I am at registration
When I provide a name of Alex
And I provide a password of 123
And I provide a description of blahblahblah
And I register the user
Then the registered user should have a username of Alex
And the registered user should have a password of 123
And the registered user should have a description of blahblahblah
Some notes on reasons for my suggestion:
I grouped the when statements together as a logical action. I'm less concerned with having all of that in the given, especially if it's not as clear.
Behind the scenes, this should make your objects easy to set up - you can map the steps to setting values on local fields or a context.
I use "the registered user" because it strikes me as a "behind the scenes" detail for your users, especially if you're trying to avoid showing ID. In your step files, you can be looking for an ID of 1, but it doesn't seem like being the first/only user is specifically a part of this test.
If you prefer a table for the example data to show people, you could still parameterize the test:
Scenario Outline: My Scenario
Given I am at registration
When I provide a name of <usersName>
And I provide a password of <password>
And I provide a description of <description>
And I register the user
Then the registered user should have a username of <usersName>
And the registered user should have a password of <password>
And the registered user should have a description of <description>
Examples:
| <usersName> | <password> | <description> |
| Alex | 123 | blahblahblah |
Though I'm not sure I'd recommend it in this specific case, as to me it seems less explicitly readable in that format.
⚠ Side note: I think this is likely just an example, but please ensure you are not storing passwords in plaintext.

Related

Table design for storing user information, license, etc

I am currently adding Google Firestore in my app so I can store user preferences, licenses, and other metadata. I have Google Authentication setup as well so I can track whatever the user is registered or not.
Not being a database/NoSQL expert, any design suggestions would be greatly appreciated!
I need to store the following, and probably more later on:
App installation / license (multiple platforms: iOS, macOS, etc.)
Bought in-app purchases (for being able to restore them from another platform)
User preferences, so they can be re-used on another platform and for backup purposes
I am thinking of this simple design:
/users (collection)
|
+-- {user_XXXXXX} <- what should be used here? e-mail? generated ID?
|
+--- app_licenses (collection)
|
+ {license_XXX} <-- incremental id? auto-generated?
| |
| +-- platform : ios / macos / ...
| +-- installation_id : device id ?
+ {license_XXX} <--- incremental id? auto-generated?
| +-- platform : ios / macos / ...
| +-- installation_id : device id ?
|
+--- iap_purchases (collection)
|
+ {iap_XXX} <--- incremental id? auto-generated?
|
+-- name : unique identifier (title/name)
+-- transaction_id
+-- date : purchase date
+--- prefs
|
+ fav_color : red / blue / ...
+ another_pref : ....
Thank you!
Your design so far looks good to me.
Regarding your root user level: Do the user's your adding information for have to be logged in through firebase? If so, I would use the user's UID from firebase. It is guaranteed to be unique and can only be retrieved after authentication.
Here's a stack overflow question concerning that.
If you aren't necessarily storing users that are logged in through firebase, I would still use some kind of auto incremented id or GUID. Just make sure you avoid the possibility of duplicate id's being generated.
I would avoid using email because perhaps further down the road you might want to add multiple emails or even phone numbers as contact info.
As for the licenses and in app purchases: I'm not quite familiar with firestore, auto incrementing id's seems like only a SQL thing to me but if you have that available to you, I think that's acceptable. GUID's would also work.

Gherkin not recognizing examples for scenario outline

I'm new to writing features in gherkin, and am getting an error on my very first scenario outline.
#language:en
Feature: Create an account
In order to become a member
As a new user
I can create an account
Scenario Outline: View the account creation page
Given I am at the "<page>" page
And I have selected "<lang>" language
When I see the Sign Up link in my language
And I click the "<size>" Sign Up link in my chosen language
Then I see the User Account page in my chosen language
And the Create New Account tab in my chosen language
Examples:
|page |lang |size |
|landing |English |large |
|landing |English |small |
|FAQ |English |large |
|Forums |English |small |
|landing |Francais |large |
|landing |Espanol |small |
When I run
cucumber --dry-run
I get the following error:
Missing Examples section for Scenario Outline at [filename].feature:8
(Cucumber::Core::Gherkin::ParseError)
Originally I had the variables in angle brackets without quotes, and added quotes following the suggestion here but alas, it didn't help with my situation.
Any ideas what my mistake is?
Thanks!

How to map URL requests for vBulletin posts to Drupal 7 Forum comments after migration?

I need help to map requests for vBulletin posts to their new location on a Drupal 7 forum.
I inherited a Drupal site after it was migrated from Drupal 5 with vBulletin, to Drupal 7 with native Drupal Forum + Advanced Forum. The new sit also uses PathAuto.
Every day I get many http requests using the old D5/vBulletin URL scheme, and there is no mapping in place to rewrite the target.
I believe I can use Apache mod_rewrite or Drupal Global Redirect to handle this, if I can map the old system to the new one.
For requests for "thread", e.g. example.com/forums/showthread.php?t=1 it seems possible to map, because the Drupal 7 path alias to the node for the thread has already been created using the existing node's title. So I can look up in the vBulletin database the old node title using the incoming query's 't' argument, edit that string according to the PathAuto settings in use on the new system, and create a URL alias. [Would love to know if there's a better way.]
But for incoming requests for "post", e.g. example.com/I can't see how to do it. The vBulletin database has the posts in the "post" table, but in Drupal 7 Forum anything after the initial post is a "comment" and has not had a URL alias created for it (because it doesn't have a title in vBulletin in most cases).
I suppose I could find the thread that the post belonged to and redirect the user to the top of the thread, as a workaround, but I'd like to have an accurate map.
Please any solutions for this ?
Drupal Migrate creates and saves tables in the database mapping the old resource ID to the new ID.
You just have to be careful since the schema are different between vBulletin and Drupal Forum; primarily in that Forum posts in D7 (other than the first post in a thread) are not nodes, but comments.
But I was able to use a Join SQL query to find the new resource ID:
mysql> SELECT m.sourceid1, m.destid1, c.cid, c.nid, c.subject FROM migrate_map_forum_posts m LEFT JOIN comment c ON c.cid = m.destid1 LIMIT 3;
+-----------+---------+-------+-------+-----------------+
| sourceid1 | destid1 | cid | nid | subject |
+-----------+---------+-------+-------+-----------------+
| 2 | 35837 | 35837 | 10426 | RE: Test |
| 3 | 35838 | 35838 | 10426 | |
| 4 | 35839 | 35839 | 10426 | I see a picture |
+-----------+---------+-------+-------+-----------------+
This solution only relies on the new Drupal 7 database and that's okay if the migration went perfectly (I guess if it was perfect the mapping would have been done at the time, lol). But the migration map tables don't always have all the data you need.
If you have access to the old vBulletin database you can dig deeper. In the migration that I inherited, some of the vBulletin 'posts' did not make it into the D7 migration map tables. But through doing more queries I was able to get the 'threadid' that the post belonged to from the vBulletin database and find the node ID for the Forum topic on D7 so I can at least get the user on to the right discussion.

Add a pop up box for each user/IP to see just 1 time

I don't know exactly what to search for when looking for info on this so here we go...
I've recently made a change to my MVC website (all the code parts are VB, not like most examples which tend to be in C#).
Once a user logs in, is there a way to show that user a pop up box, or a div, which simply explains the changes made (the text in the box is not important).
I only want the user to see this ONCE!
Example:
As soon as the user goes to the URL, they get a pop up box saying "You now have to add your name when creating a new post"
But of course, the user doesn't want to see this EVERY time they log on to the page.
Any pointers would be lovely,
Cheers.
You would need to in some way track that users have seen the message. If there's any likelihood that there will be future such messages, maybe any value in tracking when users saw the message, etc. then this can all be put into a fairly simple database structure.
Maybe a lookup table of messages:
ID | Message
-------------
1 | "This is the text of the message, or maybe the whole HTML, or some other data, it's up to you."
2 | "Other message, etc."
And a table to link that to users:
UserID | MessageID | DisplayedOn
--------------------------------
123 | 1 | 2014-01-30 08:56:21
You can even make the messages more "interactive" and have an "Accept" or "I Understand" button, requiring that the user accept the message or see it again until they do. For something like that you can change DisplayedOn to FirstDisplayedOn (maybe include a LastDisplayedOn?) and also an AcceptedOn to track that interaction. This could be very useful for updates to terms of service, for example.
Then when a user logs in, when you fetch the overall user context/object from the database you would include any messages they need to see, haven't seen yet, haven't accepted yet, etc. Your UI can then display whatever it needs to display based on that.
As you want to show popup only after user has logged you need to store information about who has seen this popup. I am guessing that you already have database and data access layer all set up. So, you need to add a new table with following columns:
Id | UserId | PopupId | ShownOn
Before displaying popup you need to query this table to see if user has already seen it. If not, just show the popup and insert a new record in data table.
As we don't know how you access your data it is impossible to give more precise solution.

How do I do if statements in Cucumber scenarios?

My app has permissions, and certain tests need to not be run when a particular permission is on, and some tests need to be run when that same permission is on.
Is there a way to do this? or do I need to use a different framework?
The standard way of excluding 'tests' in Cucumber is to add a tag to them to identify them, then when invoking Cucumber you specify which tags to include/exclude. In your example, you could tag a specific scenario:
#needs_permission
Scenario: View users billing information
Or tag the whole feature:
#needs_permission
Feature: Administrative area
Scenario: View users billing information
Or tag certain examples in a scenario outline:
Scenario Outline: Visit a page
Given I visit "<page>"
Examples: Don't need permission
| page |
| index |
| sitemap |
#needs_permission
Examples: Do need permission
| page |
| admin |
Now, when you run Cucumber, you can exclude those tags if necessary:
When the permission is on and you want to run all tests:
cucumber .
When the permission is off and you want to exclude the tests that need it:
cucumber . -t ~#needs_permission
An alternative which I have used with mixed results, if you really don't know ahead of time, is to mark a step as pending if it doesn't apply given the current scenario, e.g.
Given /^I visit some page which needs permission$/ do
pending "Permissions aren't enabled - skipping" unless permissions_enabled?
end
This will mark the step as 'pending' which really means 'not fully implemented', which isn't ideal, especially if you have many such steps - it can be difficult to ensure that other unimplemented steps don't accidentally creep in and get hidden by all the ones you've deliberately marked as such.
We get a similar instance of this a lot, we have 2 solutions,
either tags as suggested, or
create different scenarios for different permission types:
Given i log in as a moderator
and there is a new post
when i view the post
Then i should see a delete button
Given i log in as a normal user
and there is a new post
when i view the post
Then i should not see a delete button
May be possible using tags. Difficult to say without more detail.

Resources