Parameterizing with examples keyword in specflow issue - selenium

Working with parameterizing through examples keyword in specflow creating an issue.
Following is my scenario and code to insert password in the Field:
Scenario Outline: Register Successfully
Given I am shown the Registration view
When I enter ComapnyName in the <CompanyName> field
And I enter UserName in the <UserName> field
And I enter Email in the <Email> field
And I enter Password in the <Password> field
And I enter ConfirmPassword in the <ConfirmPassword> field
And I choose to register my account
Then my user account is created
And I am navigated to my company dashboard
Examples:
| CompanyName | UserName | Email | Password | ConfirmPassword |
| XYZ | Salman Haider | salman.haider#gmail.com | FooBar#123 | FooBar#123 |
public void Password(string password, int n)
{
//Getting and Setting up the values in the Password Field
var passwords = Helper.Driver.FindElements(By.XPath(".//*[#name='password']")).ToList();
passwords[n].SendKeys(password);
Thread.Sleep(2000);
}
When it enters the password in the field and clicks on submit button shows a validation error that password should be 8 characters long,one capital and a special character required besides the password is all correct. However same code works working with parameterizing with table.
Scenario: Register Successfully
Given I am shown the Registration view
When I enter credientials
| CompanyName | UserName | Email | Password | ConfirmPassword |
| Seven | Mobeen | usama.rafiq#gmail.com | FooBar#123 | FooBar#123 |
And I choose to register my account
Then my user account is created
And I am navigated to my company dashboard
. But I need former method to work as I have multiple test data to enter.

Related

Splunk subsearch is not returning the data I expect it to return

I have:
index="myIndex"
source="mySource1"
source="mySource2"
mySource1 example
2023-02-01 17:00:01 - Naam van gebruiker: hank - Rol van gebruiker: operator
2023-02-02 17:00:01 - Naam van gebruiker: skylar - Rol van gebruiker: operator
2023-02-03 17:00:01 - Naam van gebruiker: walt - Rol van gebruiker: operator
2023-02-02 17:00:01 - Naam van gebruiker: skylar - Rol van gebruiker: administrator
2023-02-03 17:00:01 - Naam van gebruiker: walt - Rol van gebruiker: administrator
mySource2 example
2023-02-06 13:49:57,654 User:hank The user is authenticated and logged in.
2023-02-07 13:49:57,654 User:skylar The user is authenticated and logged in.
2023-02-08 13:49:57,654 User:walt The user is authenticated and logged in.
2023-02-03 13:49:57,654 User:hank The user is authenticated and logged in.
2023-02-02 13:49:57,654 User:skylar The user is authenticated and logged in.
2023-02-01 13:49:57,654 User:walt The user is authenticated and logged in.
In Splunk I need a dashboard, with a statisticstable, looking like this:
USER, LATEST
hank, 2023-02-03 13:49:57,654 User:hank The user is authenticated and logged in.
skylar, 2023-02-02 13:49:57,654 User:skylar The user is authenticated and logged in.
walt, 2023-02-01 13:49:57,654 User:walt The user is authenticated and logged in
Where USER is column 1 and LATEST column 2. The purpose of the table is to show the user id's (found in mySource1) and show the latest login event (found in mySource2) so that you can tell when each user last logged in.
Initially I tried this:
index="myIndex"
source="mySource1"
| fields _time, _raw
| rex "Naam van gebruiker: (?<USER>.+) -"
| dedup USER
| table USER
| sort USER
| join type=left
[ search
index="myIndex"
source="mySource2"
"User:myUserID The user is authenticated and logged in."
| stats latest(_raw)
]
But I found out that I the second search, returns data to the first search. Also, I did not fetch the name from the second search. I later tried the following:
index="myIndex" source="mySource2"
"The user is authenticated and logged in."
| rex "User:(?<USER>\w+) The user is authenticated and logged in."
| search [search index="myIndex"
source="mySource1"
| rex "Naam van gebruiker: (?<USER>.+) -"
| dedup USER
| table USER
| sort USER
| format]
| stats latest(_raw) by USER
But this does not return any data. I tried running both searches seperately, and when I do, they return the data I need:
index="myIndex" source="mySource2"
"The user is authenticated and logged in."
| rex "User:(?<USER>\w+) The user is authenticated and logged in."
| table USER
| dedup USER
index="myIndex"
source="mySource1"
| rex "Naam van gebruiker: (?<USER>.+) -"
| dedup USER
| table USER
| sort USER
But once combined, no data is returned.
How do I manage to return the data and get the desired table of results?
EDIT: Forgot to mention, I also need to show users who have a role (source1) but have never logged in (not found in source2). Hence mySource1 is used.
You should be able to combine it all in one go:
index=ndx (source=source1 OR source=source2)
| rex field=_raw "Naam[^:]+:\s(?<user1>\S+)
| rex field=_raw "User:(?<user2>\S+)\s(?<msg>.+)
| eval user=coalesce(user1,user2)
| stats max(_time) as _time latest(msg) as msg by user
What this does: extract two field (user1 & user2) from your two sources
coalesce them into one field named "user"
Report the most recent msg for that user and the most recent _time you have an event for
(You should be able to abbreviate this slightly by using the same named field extraction (user) instead of two with a coalesce, I just wanted it to be clear)
edit to add users that have never logged in
index=ndx source=source1
| rex field=_raw "Naam[^:]+:\s(?<user>\S+)[^:]+:\s(?<role>\w+)"
| stats values(role) as roles by user
| append
[search index=ndx source=source2
| rex field=_raw "User:(?<user>\S+)\s(?<msg>.+)
| stats latest(msg) as msg max(_time) as msg_time by user ]
| stats values(*) as * by user
| where isnull(msg)
Here we're looking for a list of all users that have roles first, then appending the latest message for each user, then stats values() them together and throw away all entries that don't have a msg field via the where clause

I want to run Scenario Outline in loop for one of the variable configurable

I have use case in which I am making server name configurable using Scenario outline for get call. But I also want to make another variable like ID configurable. I want using that id it should run for all server name mentioned in Scenario Outline. How can we achieve that?
Example
Scenario Outline: Test one get call
Given url: 'https://' + server+ 'v1/share/12345/profit'
When method get
Then status 200
Examples:
|server|
|server1|
|server2|
|server3|
|server4|
In above example server name, I made it configurable using scenario outline, but I want to make number entered in URL configurable & want that to run for all servers. How I will achieve that?
Just use another variable.
Examples:
| server | id |
| foo | 1 |
| foo | 2 |
| bar | 1 |
| bar | 2 |
And if you want to dynamically generate data using a function, all that is possible. Refer: https://github.com/karatelabs/karate#json-function-data-source

How can i create a Laravel API to show ads added by admin based on impression count of users?

I've an admin side in my laravel project where admin can add Ads along with impression and hours. For e.g if i add a add with impression = 2 and hours = 2. So, once the user have viewed this ad for 2 times then user will not be shown that Ad for the next 2 hours.
Here is the structure of admin ads table:
--------------------------------------
id | image |impressions| hours |
1 | image.png| 2 | 6 |
--------------------------------------
And there's ads_impression_log where i store the log of users who have viewed an ad
---------------------------------------------
id | user_id | ad_id | impression_datetime |
1 | 1 | 1 | 2020-07-28 23:22:45 |
---------------------------------------------
How can i create a laravel query so, that i get specific ad impression count and if impression count is within the hours show the user next ad.
This is my first question here. So, please ignore if there's some mistake :)
Ad Model
public function users(){
return $this->belongsToMany(App\Add, 'ads_impression_log', 'ad_id', 'user_id')
->withPivot('impression_datetime');
}
User Model
public function ads(){
return $this->belongsToMany(App\Add, 'ads_impression_log', , 'user_id', 'ad_id')
->withPivot('impression_datetime');
}
Impression count of a given user($user_id) for a given ad.($user_id)
We'll use the collection method filter here.
$user = User::with('ads')->find($user_id);
//
$ads = $user->ads->filter(function($value, $key){
return $value->id === $ad_id;
});
Now you can get the count of those impressions.
$count = $ads->count();
Impressions required for that ad.
$ads->first()->impression;
You can do the comparison accordingly.
And to get the impression_date column from the pivot table you could do the following.
foreach($ads as $adImp){
$adImp->pivot->impression_date;
}

How can i update email column with appending some text in a particular place in Postgresql

I want to update my email column like this
|id (int) | email(varchar) | is_subscribed(boolean)
---------------------------------------------------------------------
| 1 | abc#gmail.com | true
| 2 | def#gmail.com | false
update email where id=1
after the update , an updated email will be like abc-cancel#gmail.con
cancel is string which i want to append
This what you are describing:
update t
set email = 'abc-cancel#gmail.com'
where id = 1;
Actually, I suspect that you want to insert the -cancel into the email. I strongly discourage this. You should be storing such information in a different column rather than destroying information in your database. But if you really must, you can use replace():
update t
set email = replace(email, '#', '-cancel#')
where id = 1;
After you do this, you will not be able to match emails in different tables, different databases, or provided from third-parties. Seems like a maintenance nightmare.

Use random var in behat tests to produce unique usernames

Right now I am creating users using something like the following
Given users:
| name | status | roles |
| kyle | 1 | authenticated user |
| cartman | 1 | admin |
Is there a possibility to add random strings in these names?
If I didn't misunderstand, you can do this instead.
Gherkin
Scenario: Create random users
Given I create "3" users
FeatureContext
var $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var $status = [0, 1];
var $roles = ['authenticated user', 'admin', 'superman'];
/**
* #Given /^I create "([^"]*)" users$/
*/
public function createDummyUsers($count)
{
for ($i = 0; $i < $count; $i++) {
$name = substr(str_shuffle($this->str), 0, 8);
$status = $this->status[array_rand($this->status, 1)];
$role = $this->roles[array_rand($this->roles, 1)];
echo "You've just created $name - $status -$role" . PHP_EOL;
}
}
Prints
You've just created mqBWAQJK - 1 - superman
You've just created WYuAZSco - 0 - admin
You've just created HCNWvVth - 1 - admin
You've just created EmLkVRpO - 1 -superman
You've just created pxWcsuPl - 1 -authenticated user
You've just created mLYrlKdz - 0 -superman
The RandomContext functionality from drupal/drupal-extension allows for usage like this:
Given I fill in "E-mail address" with "<?username>#example.org"
or
Given users:
| name | email | status | roles |
| <?standard> | <?standard>#example.org | 1 | authenticated |
| <?admin> | <?admin>#example.org | 1 | admin |
Each token (eg <?username>, <?firstname>) used in a feature will be randomly transformed with a (random string) value for that feature execution. This is implemented with the use of Behat's #Transform functionality, meaning that your tokens will be substituted before execution of that step - so it works to generate random inputs anywhere you might need to use random input as part of your feature.
You can reference the same token later in your feature, eg to verify that the random value input earlier has been returned correctly, and the randomly generated value will be recalled. So, the first and second usages of <?admin> in the example above will both be replaced by the same generated value.
If you are using drupal/drupal-extension then this can be enabled by adding Drupal\DrupalExtension\Context\RandomContext to the enabled contexts in your behat.yml.
If you aren't using Drupal, then the source linked above will demonstrate how you could implement the same for your own usage.
I've created a solution on that you can try.
https://github.com/JordiGiros/MinkFieldRandomizer
MinkFieldRandomizer is a random (with sense) information generator for filling browser form fields in Behat Mink Selenium tests. It brings the option to run your tests in a more realistic way changing the information you use to fill in the forms in every test you run.
You can easily add it to your project by Composer.
One example:
Then Fills in form fields with provided table
| "f_outbound_accommodation_name" | "{RandomName(10)}" |
| "f_outbound_accommodation_phone_number" | "{RandomPhone(9)}" |
| "f_outbound_accommodation_address_1" | "{RandomText(10)}" |
I hope you try it!
And you're welcome to add new functionalities or fork it or do wathever you want.
Cheers