Accessing the Scenario Title and Example in a Cucumber After hook - ruby

How can I get the current Example out of a Ruby cucumber test in an After hook?
I can get the title with the code below. My Scenario has several Examples with it. Can I access the current Example being tested?
Feature file
Scenario Outline: Successful login with primary accounts
Given I start on the login page
When I log into Overview page with "<acct>"
Then I am on the Overview page
Examples:
| acct |
| account1 |
| account2 |
After hook
After do |scenario|
scenario.scenario_outline.title # will give me the title
How to I get the current Example?

Here is how I did it.
scenario_title = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.title : ''
scenario_title_example = scenario.respond_to?(:name) ? scenario.name : ''
scenario_full_title = scenario_title + scenario_title_example

Related

Prevent NFC Service app from opening when reading empty tag with enableReaderMode

Moving from the enableForgroundDispatch (I don't seem to get it working on api 32) intent based way of reading NFC-tags to enableReaderMode. The latter one works well, but every now and then the NFC Service app is opening, showing 'emtpy tag' message. Is there a way to disable this, in code? It's true that the tags are empty, only reading and using the tag Id. Code look like the following;
Bundle opts = new Bundle();
opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 250);
getNfcAdapter().enableReaderMode(this, tag -> {
// passing tag to get tag.getId()
myViewModel.setTag(tag);
}, NfcAdapter.FLAG_READER_NFC_A |
NfcAdapter.FLAG_READER_NFC_B |
NfcAdapter.FLAG_READER_NFC_F |
NfcAdapter.FLAG_READER_NFC_V |
NfcAdapter.FLAG_READER_NFC_BARCODE |
NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK |
NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS
, opts);

Why does the first response takes more time in GAS web app?

Edit: I am using clasp. Updated the code to the actual GAS!
I have a GAS deployed as a web app. We send POST requests from Slack via a slash command and it needs a response in less than 3000ms because GAS can't handle asynchronous code.
At the first request, it takes more than 3000ms to send a response but on the following requests, it is around 1500ms.
The doPost function looks like the following.
var exports = exports || {};
var module = module || { exports: exports };
Logger = BetterLog.useSpreadsheet('spreadsheetId');
function doPost(request) {
var startExecutionDate = new Date();
var path = request.parameter.path;
Logger.log("Request received with path: " + path);
var response = Responses.Error;
var token = request.parameter.token;
if (path.startsWith('/slack')) {
Logger.log("Slack request");
var slackRouter = new SlackRouter();
response = slackRouter.post(request);
// ...
}
// ...
}
And this is the code for the Slack Router.
var exports = exports || {};
var module = module || { exports: exports };
var SlackRouter = (function () {
function SlackRouter() {
}
SlackRouter.prototype.post = function (request) {
var path = request.parameter.path;
switch (path) {
case Routes.Team:
Logger.log("For team");
// ...
}
};
return SlackRouter;
}());
exports.SlackRouter = SlackRouter;
I have the timestamps for each log.
First attempt
| Timestamp | Delta in ms | Log Message |
|--------------|-------------|---------------|
| 11:22:34:164 | 0 | Path: ... |
| 11:22:35:354 | 1190 | Slack request |
| 11:22:35:462 | 108 | For team |
Second attempt
| Timestamp | Delta in ms | Log Message |
|--------------|-------------|---------------|
| 11:22:45:047 | 0 | Path: ... |
| 11:22:45:164 | 117 | Slack request |
| 11:22:45:350 | 186 | For team |
I had several ideas already like the web app goes to a sleep state but since we calculate delta from the first log message it doesn't make sense.
So what is going on behind the scenes? Are you aware of any easy workarounds? If possible I don't want to build a microservice to send a response to Slack in time and later send the actual response.
The Apps Script servers don't keep every script ever written or deployed loaded in memory, and so scripts that haven't been run in a while need to be loaded from disk first. This is usually referred to as a "cold start time" in Cloud providers.
Answered by Eric Koleda on Google Apps Script Community forum
The most glaring issue is your use of ES6 syntax in your doPost() method.
Google Apps Script does not support ES6 template string syntax and only partially supports destructuring assignments. So that might be your issue. Your doPost() probably fails to return a value as a result so Slack likely repeats the request until it times out.
Try removing the BetterLog library. That may be causing the initial first-time delay.
https://developers.google.com/apps-script/guides/libraries
Warning: A script that uses a library does not run as quickly as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, you should use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in add-ons.

What is the test case format in gherkin language?

I have a mock up profile page of a gym and I'm to write test cases for editing that profile page in gherkin language. I don't the gherkin test case format. Can anyone please help me with this?
There is no hard and fast rule to write the gherkin tests. But it is highly advisable that you write them by following recommended procedures, to make it understandable. The main purpose of gherkin is for someone apart from your team, understand the whole testing process.
There are three primary, conditions that you will have to satisfy writing gherkin.
Start your tests with the pre-defined statements i.e Given Then and When. Your feature file should have steps that should look like these:
Given I land on homepage
When I click on the signup button
Then I see the error
There are also other keywords like:
And - Connect more than two steps
Please refer to this documentation for more details:
https://github.com/cucumber/cucumber/wiki/Given-When-Then
In my opinion, this question has no scope; however, I'll try to answer. Gherkin is a language with no technical barriers; it enforces an entire team to write unambiguous requirement-based test specifications based on creative collaboration rather technical specifics. The base components of Gherkin have been explained in the first answer. So, I'd rather try to give a working example as requested in the question to understand the use of Given, When, Then clearly.
The following test (called test specification) is written in Gherkin in the feature file:
Feature: Google Book Searching from https://www.googleapis.com/books/v1/volumes?q={ID}
Scenario Outline: Verify that the response status code is 200 and content type is JSON.
Given webService endpoint is up
When user sends a get request to webService endpoint using following details
| ID | <ID> |
Then verify <statusCode> and <contentType> from webService endpoint response
Examples:
| ID | statusCode | contentType |
| 1 | 200 | "application/json; charset=UTF-8" |
| 9546 | 200 | "application/json; charset=UTF-8" |
| 9 | 200 | "application/json; charset=UTF-8" |
Now here is the step definition for the above test specification:
// for **Given** - as it has to ensure that the required webservice end-point is up:
#Given("webService endpoint is up")
public void webserviceEndpointIsUp() {
requestSpecification = new RequestSpecBuilder().
setBaseUri(prop.getProperty(BASE_URL)).
build();
}
// for **When** - as this is for the part when user sends the request to the webservice end-point and receives the response
#When("user sends a get request to webService endpoint using following details")
public void userSendsAGetRequestToWebServiceEndpointUsingID(Map<String, String> data) {
String ID = data.get("ID");
System.out.println("The current ID is: " + ID);
String pathParameters = "?q" + "=" + ID;
response = given().
spec(requestSpecification).
when().
get(pathParameters);
}
// for **Then** - finally, here is the then part. When we're verifying the actual stuff mentioned in the Scenario
#Then("verify {int} and {string} from webService endpoint response")
public void verifyResponseStatusCodeAndContentTypeFromWebServiceEndpointResponse(int statusCode, String contentType) {
Assert.assertEquals(statusCode, response.getStatusCode());
Assert.assertEquals(contentType, response.getContentType());
}
This is just one example that how tests are written in Gherkin, there is a lot more to learn to be able to write such scripts. So, I'll recommend to start off with the following links:
Writing Good Gherkin
Cucumeber-JVM Free Course

Laravel : login from one subdomain to another subdomain : session issue

I am using Sentry on laravel 4.2 in one application with muti-subdomain (every domain have different users) : i want to login from one subdomain(domain-a.maindomain.com) to another subdomain(domain-b.maindomain.com) without persisting session across subdomain.
Any one have idea how can i achieve this with laravel
i think Since the Laravel authentication system uses cookies to manage the session, you actually need to login the user on each subdomain you're going to use. To avoid that, you can use another session driver like database. and what #SUB-HDR give you in his comment is a good way too do it.
I'm not familiar with Laravel before version 5.1 but there is part of the documentation which relates to authentication:
https://laravel.com/docs/4.2/security
$user = User::find(1);
Auth::login($user);
With this you may be able to authenticate a user from one of your domains to the other. You would need to pass something from the first domain to the second domain which is a unique common attribute between the two user models and then authenticate the matching user.
in (php / mysql) we can made a row called IslogedIn(or something else you prefer) in All your Databases so they''ll look like :
//---------------------------------------------
// (main database) --> site1.com
// ------------------------------------------
// | id | username | password | IslogedIn |
// |-----|-----------|----------|-------------|
// | 1 | jhony | pass | 0 |
// |-----|-----------|----------|-------------|
//---------------------------------------------
// (2nd database) --> site2.com
// ------------------------------------------
// | id | username | password | IslogedIn |
// |-----|-----------|----------|-------------|
// | 1 | jhony | pass | 1 |
// |-----|-----------|----------|-------------|
here for example we see the user is logged in 2nd database
so the value will be : IslogedIn = 1
and we gonna use that in all our domains and from "login.php" (in Laravel it can be somthing else) , from "login.php" we mark IslogedIn = 1 if the user logged in by using some mysql orders .
after that we connect all databases using a scrip page and name it something like : 'checkout.php' in both domains folders and write in it :
1 - for old php versions :
$Db_Main_con = mysql_connect($hostname, $username, $password );
$Db_2nd_con = mysql_connect($hostname, $username, $password , true);
//-------------------------------------------------------------
$Db_Main_Select = mysql_select_db("Database_name1", $Db_Main_con);
$Db_2nd_Select = mysql_select_db("Database_name2", $Db_2nd_con );
//-------------------------------------------------------------
$Db_main = mysql_query("select * from users where id = :id", $Db_Main_Select);
$Db_2nd = mysql_query("select * from users where id = :id", $Db_2nd_Select);
2 - for new version is Generally similar only some changes in the past code , such as mysql to mysqli . read this article : mysqli_connect
and I'm not familiar with Laravel so ofc you change the "$host_main_name" and "$username" and ( table name )..... etc to feet your script
and from every db call the row : (IslogedIn) in a $string.
then we go to check if the user is Logedin in all Db we have :
if ( $Db_Main->IslogedIn || $Db_2nd->IslogedIn )
{
// ----->> your login code or relogin code here
// + sessions and cookies and reloud link and all other stuff
}
then we close the script with $Db_Main->close(); $Db_2nd->close(); .... etc when the checkout is end .

Pull scenario outline (or read a tag) from within cucumber step

If I have a scenario that starts like this:
#my-tag
Scenario Outline:
Admin user changes email
Given I register a random email address
...
is it possible to read either the scenario outline text or the #my-tag in an individual step definition? For example, in the I register a random email address step I'd like to print debug info if it's running under a given scenario or a tag value.
You cannot access that information directly from within a step definition. If you need the information, you will have to capture it during a before hook.
Cucumber v3+
The following before hook will capture the feature name, scenario/outline name and the list of tags. Note that this solution is for Cucumber v3.0+. For earlier versions, see the end of the answer.
Before do |scenario|
# Feature name
#feature_name = scenario.feature.name
# Scenario name
#scenario_name = scenario.name
# Tags (as an array)
#scenario_tags = scenario.source_tag_names
end
As an example, the feature file:
#feature_tag
Feature: Feature description
#regular_scenario_tag
Scenario: Scenario description
Given scenario details
#outline_tag
Scenario Outline: Outline description
Given scenario details
Examples:
|num_1 | num_2 | result |
| 1 | 1 | 2 |
With step defined as:
Given /scenario details/ do
p #feature_name
p #scenario_name
p #scenario_tags
end
Will give the results:
"Feature description"
"Scenario description"
["#feature_tag", "#regular_scenario_tag"]
"Feature description"
"Outline description, Examples (#1)"
["#feature_tag", "#outline_tag"]
You could then check the #scenario_name or #scenario_tags for your conditional logic.
Cucumber v2
For Cucumber v2, the required hook is a more complicated:
Before do |scenario|
# Feature name
case scenario
when Cucumber::Ast::Scenario
#feature_name = scenario.feature.name
when Cucumber::Ast::OutlineTable::ExampleRow
#feature_name = scenario.scenario_outline.feature.name
end
# Scenario name
case scenario
when Cucumber::Ast::Scenario
#scenario_name = scenario.name
when Cucumber::Ast::OutlineTable::ExampleRow
#scenario_name = scenario.scenario_outline.name
end
# Tags (as an array)
#scenario_tags = scenario.source_tag_names
end
The output is slightly different:
"Feature description"
"Scenario description"
["#regular_scenario_tag", "#feature_tag"]
"Feature description"
"Outline description"
["#outline_tag", "#feature_tag"]

Resources