@7edge-mangalore/authentication
v1.1.0
Published
Reusable authentication library for ZoodPay test automation
Readme
Authentication Library
A reusable, production-ready authentication library for the ZoodPay Distributor Web Application automation framework.
📁 Structure
test/authentication/
├── features/ # Gherkin feature files
│ └── login.feature # Reusable login scenarios
├── step-definitions/ # Cucumber step definitions
│ └── authenticationSteps.cjs
├── services/ # Core authentication logic
│ └── AuthenticationService.cjs
├── config/ # User configurations
│ └── userConfig.cjs
└── README.md # This file🚀 Quick Start
Basic Usage in Feature Files
Feature: My Feature
Background:
Given Tom is in login page
When Tom logs in as "masterDistributor" using "email" method
And Tom verifies OTP with value "999999"
Then Tom should be successfully logged in
Scenario: Test something after login
Given Tom is logged in
When Tom performs some action
Then Tom should see expected resultUsing in Step Definitions
const { AuthenticationService } = require('../authentication/services/AuthenticationService.cjs');
// In your Before hook
Before(async function() {
this.authService = new AuthenticationService(global.page);
});
// In your step definitions
When('Tom performs authenticated action', async function() {
// Login if not already logged in
if (!await this.authService.isLoggedIn()) {
await this.authService.login({
method: 'email',
identifier: '[email protected]',
password: 'password123',
otp: '999999'
});
}
// Continue with your test logic
});📚 API Reference
AuthenticationService
Methods
login(credentials)
Complete login flow with OTP verification.
Parameters:
credentials.method(string):'email'(primary method used)credentials.identifier(string): Email addresscredentials.password(string): User passwordcredentials.countryCode(string, optional): Country code (not used for email)credentials.otp(string, optional): OTP value (default: fromTEST_OTPenv var or'999999')credentials.skipOTP(boolean, optional): Skip OTP verification (default:false)credentials.verifyDashboard(boolean, optional): Verify dashboard redirect (default:true)
Returns: Promise<Object> - Login result with user info
Example:
await authService.login({
method: 'email',
identifier: '[email protected]',
password: 'password123',
otp: '999999'
});loginWithUserType(userType, config)
Login with pre-configured user credentials.
Parameters:
userType(string): User type from config (e.g.,'masterDistributor')config(Object): User configuration object
Example:
const { getUserConfig } = require('./config/userConfig.cjs');
const config = getUserConfig('masterDistributor', 'email');
await authService.loginWithUserType('masterDistributor', { masterDistributor: config });logout()
Logout from the application.
Example:
await authService.logout();isLoggedIn()
Check if user is already logged in.
Returns: Promise<boolean>
Example:
const loggedIn = await authService.isLoggedIn();🎯 Available Step Definitions
Navigation
Given Tom is in login page- Navigate to login page
Login Methods
When Tom logs in using {method} with identifier "{identifier}" and password "{password}"When Tom logs in as "{userType}" using "{method}" methodWhen Tom logs in with default credentials
OTP Verification
When Tom verifies OTP with value "{otp}"When Tom verifies OTP(uses default OTP: 999999)
Verification
Then Tom should be successfully logged inThen Tom should see welcome message "{message}"Then Tom should be redirected to the OTP verification pageThen Tom sees login by default opted as email
Logout
When Tom logs out
⚙️ Configuration
User Configuration
Edit config/userConfig.cjs to add or modify user credentials:
const userConfig = {
masterDistributor: {
email: {
method: 'email',
identifier: '[email protected]',
password: 'password123',
otp: '999999'
}
}
};Environment Variables
You can override default credentials and OTP using environment variables:
export [email protected]
export TEST_USER_PASSWORD=password123
export TEST_OTP=123456 # Configurable OTP - overrides default '999999'
export SKIP_OTP=falseOTP Configuration:
- The OTP is fully configurable via the
TEST_OTPenvironment variable - If
TEST_OTPis not set, it defaults to'999999'(test environment default) - OTP can be set per user in
userConfig.cjsor globally via environment variable - When using step definitions, OTP will automatically use the configured value
🔒 Security Best Practices
- Never commit real credentials - Use environment variables or secure vaults
- Use test accounts only - Never use production credentials
- Rotate test credentials - Regularly update test account passwords
- Use secrets management - In CI/CD, use Azure Key Vault, AWS Secrets Manager, etc.
📝 Examples
Example 1: Simple Login in Feature File
Feature: Dashboard Tests
Background:
Given Tom is in login page
When Tom logs in as "masterDistributor" using "email" method
And Tom verifies OTP with value "999999"
Then Tom should be successfully logged in
Scenario: View dashboard
Given Tom is logged in
When Tom navigates to dashboard
Then Tom should see dashboard elementsExample 2: Programmatic Login in Step Definitions
const { Given } = require('@cucumber/cucumber');
const { AuthenticationService } = require('../authentication/services/AuthenticationService.cjs');
Given('Tom is logged in', async function() {
if (!this.authService) {
this.authService = new AuthenticationService(global.page);
}
if (!await this.authService.isLoggedIn()) {
await this.authService.login({
method: 'email',
identifier: '[email protected]',
password: 'password123',
otp: '999999'
});
}
});Example 3: Using Different Login Methods
Scenario Outline: Login with different methods
Given Tom is in login page
When Tom logs in using <method> with identifier "<identifier>" and password "<password>"
And Tom verifies OTP with value "999999"
Then Tom should be successfully logged in
Examples:
| method | identifier | password |
| email | [email protected] | pass123 |🔄 Integration with Existing Tests
To use this library in your existing feature files:
Import step definitions in your Cucumber configuration:
// In cucumber.js or test runner require('./test/authentication/step-definitions/authenticationSteps.cjs');Use in Background of your feature files:
Feature: My Feature Background: Given Tom is in login page When Tom logs in as "masterDistributor" using "email" method And Tom verifies OTP Then Tom should be successfully logged inOr use programmatically in your step definitions:
const { AuthenticationService } = require('../authentication/services/AuthenticationService.cjs');
🧪 Testing the Library
Run the authentication feature file:
npx cucumber-js test/authentication/features/login.feature --require test/authentication/step-definitions📋 Supported Login Methods
- Email Login - Login using email address and password (primary method)
OTP verification is required after initial credentials are submitted. OTP is configurable via TEST_OTP environment variable.
🐛 Troubleshooting
Issue: Step definition not found
Solution: Ensure step definitions are loaded in your Cucumber configuration:
require('./test/authentication/step-definitions/authenticationSteps.cjs');Issue: Login fails
Solution:
- Check user credentials in
config/userConfig.cjs - Verify OTP value (default is
999999for test environment) - Check if login page URL is correct
Issue: OTP verification fails
Solution:
- Ensure OTP value matches test environment (usually
999999) - Check OTP input field selectors
- Verify OTP page is loaded before entering OTP
🤝 Contributing
When adding new authentication methods or features:
- Update
AuthenticationService.cjswith new methods - Add corresponding step definitions in
authenticationSteps.cjs - Update
userConfig.cjswith new user types if needed - Add feature scenarios in
login.feature - Update this README with new functionality
📄 License
Internal use only - ZoodPay Distributor Web Application
👥 Maintainers
QA Automation Team
Last Updated: 2024 Version: 1.0.0
