external-services-automation
v1.0.40
Published
External services automation library for Playwright and Cucumber
Maintainers
Readme
External Services Automation Library
A TypeScript library for test automation with Playwright, focused on integrations with external services like Kinde (authentication) and Stripe (payments).
Installation
Install the package via npm:
npm install external-services-automationSetup
Environment Variables
For email testing with GetTestMailService, configure:
export TESTMAIL_API_KEY=your_api_key
export TESTMAIL_NAMESPACE=your_namespaceGet your credentials from testmail.app/console.
Configure Your Test Framework
The library can be used with any test framework. Here's an example for Playwright:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
use: {
baseURL: process.env.BASE_URL || 'https://your-app.com',
},
});Usage
Import Components
import {
ExternalServicesWorld,
LoginPage,
RegisterPage,
StripeService,
GuerrillaMailService,
GetTestMailService
} from 'external-services-automation';Use Services and Page Objects
// Payment processing with Stripe
const stripeService = new StripeService();
await stripeService.upgradeSubscription(planType);
// Email testing with GetTestMail
const mailService = new GetTestMailService(
process.env.TESTMAIL_API_KEY!,
process.env.TESTMAIL_NAMESPACE!
);
const email = mailService.createEmailAddress('test-user');
// Page interactions
const loginPage = new LoginPage(page);
await loginPage.fillCredentials(email, password);Available Components
Services
StripeService
upgradeSubscription(planType: string)- Upgrades subscription to specified planupdatePaymentMethod(cardDetails: object)- Updates payment methodgetCurrentSubscription()- Retrieves current subscription details
Page Objects
Kinde Pages
- LoginPage - Handles login form interactions
- RegisterPage - Manages account registration
- ConfirmCodePage - Email verification code entry
- PasswordSetupPage - Password creation and setup
Stripe Pages
- CurrentSubscriptionPage - Displays current subscription details
- UpdateSubscriptionPage - Subscription plan selection
- UpdatePaymentMethodPage - Payment method management
- ConfirmUpdatePage - Confirmation dialogs
- LeftPanelPage - Navigation and sidebar interactions
Email Services
GuerrillaMailService
Temporary email service (free, but can be unstable):
createMail(alias?)- Creates temporary email addressreadMailBySubject(regex, timeoutMs?, pollMs?)- Waits for email matching subject
GetTestMailService ⭐ Recommended
Professional temporary email service with reliable API:
createEmailAddress(tag)- Generates email with custom taggetEmails(tag?, timestampFrom?, livequery?)- Retrieves emails with filteringreadMailBySubject(tag, regex)- Waits for email matching subjectextractCode(email, pattern?)- Extracts verification codes- Requires API key from testmail.app
See GetTestMailService documentation for detailed usage.
World Extension
- ExternalServicesWorld - Shared state management for test scenarios
Example Implementation
// In your test files
import { test, expect } from '@playwright/test';
import { StripeService, GetTestMailService } from 'external-services-automation';
test.describe('External Services Integration', () => {
let stripeService: StripeService;
let mailService: GetTestMailService;
test.beforeEach(async () => {
stripeService = new StripeService();
mailService = new GetTestMailService(
process.env.TESTMAIL_API_KEY!,
process.env.TESTMAIL_NAMESPACE!
);
});
test('should handle email verification flow', async () => {
// Create temporary email for account verification
const tag = `signup-${Date.now()}`;
const email = mailService.createEmailAddress(tag);
// Register new account (your implementation)
await registerUser(email);
// Wait for verification email and extract code
const verificationEmail = await mailService.readMailBySubject(
tag,
/verification code/i,
120000
);
const code = mailService.extractCode(verificationEmail);
// Confirm registration with code (your implementation)
await confirmRegistration(code);
});
test('should upgrade subscription', async () => {
await stripeService.upgradeSubscription('premium');
const subscription = await stripeService.getCurrentSubscription();
expect(subscription.status).toBe('active');
});
});Updates
To update to the latest version:
npm update external-services-automationCI/CD
Bitbucket Pipelines
script:
- npm install
- npm testDependencies
The library requires the following peer dependencies to be installed in your project:
npm install @playwright/test axios-cookiejar-support dotenv tough-cookieVersion requirements:
@playwright/test^1.40.0axios-cookiejar-support^6.0.2dotenv^16.4.5tough-cookie^5.1.2
Troubleshooting
Package Not Found
npm install external-services-automationImport Errors
Make sure you're importing from the correct package name:
import { StripeService, GetTestMailService } from 'external-services-automation';Missing Peer Dependencies
npm install @playwright/test axios-cookiejar-support dotenv tough-cookieDevelopment
For contributors working on this library:
git clone https://bitbucket.org/connectist/external-services-automation.git
cd external-services-automation
npm install
npm run buildLinks
- NPM Package: https://www.npmjs.com/package/external-services-automation
- Repository: https://bitbucket.org/connectist/external-services-automation
