Feature files are not running in defined order on Selenium junit? - cucumber

My Feature files:
test.feature
#Login
Feature: A Login Feature
Verify if user is able to Login in to the site
Scenario Outline: Login as a authenticated user
Given user is on homepage
When user navigates to Login Page
And user enters "username" and "Password"
Then success message is displayed
logout.feature
#Signout
Feature: Logout validations
Verify if user is able to Login in to the site
Scenario: sce to logout validtaions
When user is on PRR portal
And user click signout button
Then Home page should load
My runner file
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"D:\ramesh\cucmbertest\src\main\java\features\test.feature","D:\ramesh\cucmbertest\src\main\java\features\Logout.feature"}
,glue= {"seleniumgluecode"},plugin = { "pretty", "html:src/cucumber-reports" },monochrome = true
)
public class testrunner {
}
My expectation is need to run "test.feature" then "logout.feature" , but logout is getting executed first. Please help me to fix this.

Related

How to pass output of 1 scenario to 2nd scenario as input

For the below scenarios, I want to use the output of #login as input for #logout...
Note- I have made 2 different step definitions for login and logout
#login
Scenario Outline: Login
Given Browser
And Link
When Enter <username> and <password>
When Enter Captcha
When Check Privacy Policy
And Click on Login
Examples:
| username | password |
| 2100070100 | 12345678 |
#logout
Scenario: Logout
Then Once Successful Login, Click Logout
Then Close The Browser
After successful login using valid login credentials, I want to click logout...
You cannot (and should not try to) pass the output of one scenario to another. The whole point of a scenario is to be an independent test that works in isolation.
You should write at least two scenarios
Scenario: I login
Scenario: I logout
The first scenario should be something like
Scenario: Login
Given I am registered
When I login
Then I should be logged in
The second scenario should be something like
Scenario: I logout
Given I am logged in
When I log out
Then I should be logged out
Now you can resume the code in When I login in Given I am logged in
Here is what I would do in a bit more detail in Rubyish pseudocode
module LoginStepHelper
def login_as(user: )
# code to login
visit login_path
fill_in 'username', user.username
fill_in 'password', user.password
submit_form
end
def logout
click_link 'Logout'
end
end
World LoginStepHelper
When 'I login' do
login_as(user: #i)
end
Given 'I am logged in' do
login_as(user: #i)
end
...

Cancelling new user signup in Azure AD B2C redirects to sites home page, produces "AuthorizationFailed" error

I have a Blazor Hosted WASM application, and am using Azure AD-B2C to secure it. If a user who is not logged in tries to access any site on the page, they are directed to our b2c login page, as they should be, and if they supply a good username and password they are allowed to view the site. So far so good. However, if the user clicks on "Sign up now", and then cancels the signup process instead of providing a new username, password, and e-mail address, then they are redirected to the site's landing page (as if they had provided a good username and password), which fails to redirect them back to the b2c login page and produces a console message reading "info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user"
The documentation suggests that I access the app's manifest and set the allowPublicClient attribute to null or true to address this problem. I have done this, and the problem persists. Why isn't the user being redirected back to the B2C login page in this case, when they normally would be if they try to access any page on the site (including this landing page) in other cases?
When the user cancels and get redirected back to the landing page, it returns an specific error code in the url (eg: AADB2C90118) in the return redirect url (In some cases it only flashes quickly because Angular removes the query string after the redirect).
You need to listen to this and handle it. You can handle it manually by parsing the return url but if you use msal.js on client side you can listen to this and start the reset password flow.
this.broadcastService.subscribe("msal:loginFailure", (error) => {
console.warn("msal:loginFailure", error);
// Check for forgot password error
// Learn more about AAD error codes at https://learn.microsoft.com/en-us/azure/active-directory/develop/reference-aadsts-error-codes
if (error.errorMessage.indexOf("AADB2C90118") > -1) {
alreadyRedirecting = true;
this.msalAuthService.loginRedirect(
b2cPolicies.authorities.resetPassword
);
}
});
The above example is for when the user clicks on forgot password link and get redirected back, so you will need to find the error code that applies to you.

Azure Custom Policies KMSI - Password Reset and Cancel Sign up redirect to authentication response url

I use this example for a B2C web app/web api authentication/authorisation. I also use Local Account custom policies and KMSI.
The issue I have is that when a user clicks forgot pwd or cancel sign up the web app redirects to the authentication redirect url (in my case xxx/azurewebsites.net/api/UserAccess) without authenticating :
The B2C example (although it was setup for User Flows and I'm using Custom Policies) already handles error exceptions when a user clicks "forgot password" - I use this same code. However my web app picks up error AADB2C90118 (click forgot password) but OnAuthenticationFailed redirects it to the authentication response url without performing authentication.
Below is Fiddler showing my webapp behaviour: click on forgot password->picks up the error->redirects to authentication response URL without authentication:
And here MSFT's example: click on forgot password->picks up error->redirects back to authentication:
Below my Start.Auth OnAuthenticationFailed, I added error AADB2C90091 to cater when the user clicks to Sign up and cancels.:
private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
notification.HandleResponse();
// Handle the error code that Azure AD B2C throws when trying to reset a password from the login page
// because password reset is not supported by a "sign-up or sign-in policy"
if (notification.ProtocolMessage.ErrorDescription != null && notification.ProtocolMessage.ErrorDescription.Contains("AADB2C90118"))
{
// If the user clicked the reset password link, redirect to the reset password route
notification.Response.Redirect("/Account/ResetPassword");
notification.Response.Redirect("/");
}
else if (notification.ProtocolMessage.ErrorDescription != null && notification.ProtocolMessage.ErrorDescription.Contains("AADB2C90091"))
{
// If the user clicked the Cancel for reset password or sign up link, redirect to login page
notification.Response.Redirect("/Account/SignUpSignIn");
}
else if (notification.Exception.Message == "access_denied")
{
notification.Response.Redirect("/");
}
else
{
notification.Response.Redirect("/Home/Error?message=" + notification.Exception.Message);
}
return Task.FromResult(0);
}
In using Custom Policies and KSMI tutorial standard files with the changes explained in the tutorial; I'm not sure if these changes would have an impact on this issue I'm finding. I attach link to xml files https://drive.google.com/drive/folders/1E9SRLaicM74YmxDxNL1_rfx4NPvX-ADJ?usp=sharing

Redirect to dynamic page after sign in

I have a multi tenant website with login via Azure AD implemented. As of now, I have setup the redirecturi to a specific page and added that page to the list of reply urls.
My question is how can I navigate to a page which is not in the reply urls after login?
I am using ASP.NET core with OpenID Connect.
Example flow:
User navigates to http://{domain}/orders/orderid where order id is dynamic. The behavior I want is that the user should be taken to the (Azure AD) login menu and after entering the credentials, user should be redirected to the same page i.e. http://{domain}/orders/orderid.
As of now, what I have is user is redirected to the Azure AD login menu, but after entering the credentials, user is taken to a predefined page ('profile') which is in the list of reply urls.
Sample code:
public IActionResult LogIn()
{
if ( !User.IsAuthenticated() )
{
return Challenge(new AuthenticationProperties { RedirectUri = "/profile" },OpenIdConnectDefaults.AuthenticationScheme);
}
else
{
return RedirectToAction(nameof(Index), "Home" );
}
}
You should firstly add [Authorize] on your orders controller . If user is not authenticated , he will be redirected to Azure AD login page .
Then use new AuthenticationProperties { RedirectUri = "/" } . After user is authenticated , he will be redirected to the original page (http://{domain}/orders/orderid)

Cucumber in a scenario session does not persist

Trying to get test the scenario where user logs (admin) and then create further users.
In log i can see that control goes to login page and then admin user logs in and when control redirects to further users creation page the login filter get halts and redirect control back to login page.
Newbie in cucumber so code is not good in quality, so any guide for testing logged in user services will be helpful
Here is my scnario
Feature: Create user from LMS
In order to create lms user with multiple groups
As a author
I want to create lms user with multipl groups
Scenario: Add new user with multiple groups
Given the following user information
And I am logged in as author "gulled" with password "thebest"
When I request for new lms user creation
Then the new user "user1" should be created
And here is the deffinitions
Given /^the following user information$/ do
# Factory(:login)
# Factory(:author)
end
Given /^I am logged in as author "([^"]*)" with password "([^"]*)"$/ do |username, password|
visit "account/login"
fill_in "loginfield", :with => username
fill_in "password", :with => password
click_button "submit_button"
end
When /^I request for new lms user creation$/ do
visit "/author_backend_lms/new_user"
fill_in "login_first_name", :with => ""
fill_in "login_last_name", :with => ""
fill_in "login_login", :with => ""
fill_in "login_email", :with => ""
fill_in "login_password_confirmation", :with => ""
click_button "create_user_form_submit_button"
end
Then /^the new user "([^"]*)" should be created$/ do |user_login|
login = Login.find_by_login user
assert_no_nil login, "Record creation failed"
end
In "request for new lms user creation" the control redirects back to login page when try to access lms user creation page.
Here is my Gem list for test
gem "capybara", "1.1.1"
gem "cucumber", "1.1.0"
gem "cucumber-rails", "0.3.2"
Looks like you are not creating the admin user beforehand in the Given the following user information step, which is making the And I am logged in as author "gulled" with password "thebest" step fail.
Try using save_and_open_page method to debug what is happening after each step.
I would rewrite the scenario as follows(without having too many unwanted detail):
Scenario: Add new user with multiple groups
Given I am logged in as an admin user
When I request for new lms user creation
Then a new user should be created
Do check out http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off for some good advice on how to write better scenarios.
EDIT
Here's an example step_definitions from one of my projects for creating the user beforehand, and logging in:
Given /^the user has an account$/ do
#user = FactoryGirl.create( :user )
end
When /^the user submits valid signin information$/ do
fill_in "user_email", with: #user.email
fill_in "user_password", with: #user.password
click_button "Sign in"
page.should have_link('Logout', href: destroy_user_session_path)
end
Using instance variables makes the user factory object persist across steps. And checking that there is a logout link at the end of the step ensures that the signin has indeed succeeded. Hope this helps in fine-tuning your step definitions.
I have a sample project which illustrates better (IMO) ways of using Cucumber to do this sort of thing. I think it might provide some of the guidance you asked for
see here
Hope its useful

Resources