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
Related
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
...
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.
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.
I'm implementing a reset password feature for users of my site. Once a verified, well-defined user signs up, a unique token is generated (specifically for this case), saved in the database, and included as a parameter in the querystring of the link included in the "Forgot password" email to the user. The user then checks their email, clicks on the link, and will be redirected to a view where they can redefine their password.
The main obstruction I am dealing with in this process is obtaining the unique token as a parameter from the link when the user clicks on that link in their email. I referenced the official Express documentation and specified the route (which is activated in the email when the user clicks on it in their inbox to go to a view to reset their password), and wrote the following route to handle it:
usersRouter.route('/reset/passwordLoggedOut/:token')
.get(emails.resetPasswordForgot);
with the ensuing resetPasswordForgot() function (minified for your viewing convenience):
function resetPasswordForgot(req, res){
const token = req.params.token;
console.log(token);
res.send(200);
}
Console.log(token) is currently showing up null when I expect it to contain the user password token.
Some more background information, I'm using SendGrid for all of my automated emails, Mailinator for testing the emails as the user, and here is what the route looks like when I hover over the link within the email. (I realize that the image is small and probably impossible to view without zooming in several times, but I wanted to include as much of the URL as possible)
Please let me know what I need to do to get the token param from the link in the email.
You need access by the query attribute:
function resetPasswordForgot(req, res){
const token = req.query.token;
console.log(token);
res.send(200);
}
I am using rails 3.0.0.beta3 to implement authlogic and subdomain-fu. And, I have a problem with automatic login into subdomain after signup.
The scenario is :
I have a signup form where an account and an admin user for that account are created simultaneously. Each time a new account is created, a separate subdomain is assigned to that account.
When the form is submitted, I expect the user to be redirected to
"user-sub-domain"."app-domain".com with the session for that sub-domain created automatically.
Currently, although the user is redirected to the corresponding subdomain, the session is not created. I think that the session is created only for the app-domain and when it is redirected to the subdomain, it doesn't find the session and thus, prompts the user to login again.
However, second-time login works fine.
I tried something like
config.action_controller.session = { :domain => '.dummy.localhost' } in development.rb. But, it doesn't seem to work. It still shows up the login form.
I would appreciate your help.
Thanks.
Look at "config/initializers/session_store.rb":
Rails.application.config.session_store :cookie_store, {
:key => 'app_session',
:domain => '.example.com' }