1+ import { test , expect } from '@playwright/test' ;
2+ import path from 'path' ;
3+ import { fileURLToPath } from 'url' ;
4+
5+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
6+
7+ test . describe ( 'Web3Auth Asset Hub Tests' , ( ) => {
8+ test . beforeEach ( async ( { context, page } ) => {
9+ // Load the stored session if it exists
10+ const sessionPath = path . join ( __dirname , 'session-data' ) ;
11+
12+ console . log ( '🔄 Loading session from:' , sessionPath ) ;
13+
14+ // Navigate to the app
15+ await page . goto ( 'http://localhost:5174' ) ;
16+ await page . waitForLoadState ( 'networkidle' ) ;
17+ } ) ;
18+
19+ test ( 'should load the Web3Auth application' , async ( { page } ) => {
20+ // Check if the main title is visible
21+ await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Web3Auth' ) ;
22+
23+ // Check if login button exists (when not logged in)
24+ const loginButton = page . locator ( 'button' , { hasText : 'Login' } ) ;
25+ const logoutButton = page . locator ( 'button' , { hasText : 'Log Out' } ) ;
26+
27+ // Should have either login or logout button
28+ const hasLogin = await loginButton . isVisible ( ) . catch ( ( ) => false ) ;
29+ const hasLogout = await logoutButton . isVisible ( ) . catch ( ( ) => false ) ;
30+
31+ expect ( hasLogin || hasLogout ) . toBe ( true ) ;
32+
33+ console . log ( '✅ Application loaded successfully' ) ;
34+ } ) ;
35+
36+ test ( 'should show Asset Hub networks in switch chain component' , async ( { page } ) => {
37+ // Look for the Switch Network section
38+ const switchChainSection = page . locator ( 'h2' , { hasText : 'Switch Network' } ) ;
39+ await expect ( switchChainSection ) . toBeVisible ( ) ;
40+
41+ // Check for Asset Hub network buttons
42+ const passetHubButton = page . locator ( 'button' , { hasText : 'Passet Hub' } ) ;
43+ const kusamaAssetHubButton = page . locator ( 'button' , { hasText : 'Kusama Asset Hub' } ) ;
44+ const westendButton = page . locator ( 'button' , { hasText : 'Westend Network' } ) ;
45+
46+ // At least one Asset Hub network should be visible
47+ const hasAssetHubNetworks = await Promise . all ( [
48+ passetHubButton . isVisible ( ) . catch ( ( ) => false ) ,
49+ kusamaAssetHubButton . isVisible ( ) . catch ( ( ) => false ) ,
50+ westendButton . isVisible ( ) . catch ( ( ) => false )
51+ ] ) ;
52+
53+ expect ( hasAssetHubNetworks . some ( visible => visible ) ) . toBe ( true ) ;
54+
55+ console . log ( '✅ Asset Hub networks are visible' ) ;
56+ } ) ;
57+
58+ test ( 'should display wallet address when connected' , async ( { page } ) => {
59+ // Check if wallet address is displayed
60+ const walletAddressSection = page . locator ( 'text=Wallet Address:' ) ;
61+
62+ if ( await walletAddressSection . isVisible ( ) ) {
63+ // If connected, should show an address or "Not connected"
64+ const addressText = await page . locator ( 'text=Wallet Address:' ) . textContent ( ) ;
65+ expect ( addressText ) . toBeTruthy ( ) ;
66+ console . log ( '✅ Wallet address section found:' , addressText ) ;
67+ } else {
68+ console . log ( 'ℹ️ Not connected - wallet address not shown' ) ;
69+ }
70+ } ) ;
71+ } ) ;
72+
73+ // Export test configuration
74+ export default {
75+ testDir : './tests' ,
76+ timeout : 30000 ,
77+ use : {
78+ headless : false ,
79+ viewport : { width : 1280 , height : 720 } ,
80+ }
81+ } ;
0 commit comments