1+ import { test , expect , Page , BrowserContext , chromium } from '@playwright/test'
2+ import { HomePage } from '../../pages/HomePage.page' ;
3+ import { TradeTradePage } from '../../pages/TradeTradePage.page' ;
4+ import { ConnectWalletPage } from '../../pages/ConnectWalletPage' ;
5+ import { EncryptedKeyPage } from '../../pages/EncryptedKeyPage' ;
6+
7+ let page : Page
8+ let browserContext : BrowserContext
9+ const encryptedLeapKey = "2SrrmLXhu2W3rX4jcELNY4GLoo6wGRVB2U7bG7uN58vokMEw8xugKW7ZdzMog2zmEGeqRx6EYfGfPEjeSGWPaebR6sECyX4Yfuo8rc1v773M3yowpKNRqJ3M5QoNbHQqCmqk59sYHVrJM8wqpZe5hvA2cak7M5oLMsLAs1rbBndsLw6fQ7FJUe3quawE8hts77aBv9RLSTRsHeLGuQcQxL15Ukgw2YxbvpGfYpheSGKDfdCJRjW9iZuw4AQwvLec9etS4a5WAZ6LkHC8kcovvaogUwyfHcKDf8w1Bz9pxZwniVvqDn6zaMF7bknJFjbPA69T7aJPQbeTqp9VEApN1r2nJYX3dCyqFJF6NcD2h2JJz"
10+ const passworld = 'Abc123456789'
11+
12+ test . beforeAll ( 'Launch browser context with permission' , async ( ) => {
13+ const browser = await chromium . launch ( )
14+ browserContext = await browser . newContext ( {
15+ permissions : [ 'clipboard-read' , 'clipboard-write' ]
16+ } ) ;
17+ page = await browserContext . newPage ( )
18+
19+ const homePage = new HomePage ( page )
20+ await homePage . goToHomePage ( )
21+ expect ( homePage . spotHistory ) . toBeTruthy ( ) ;
22+ //await homePage.carbonTestnet.click();
23+ //await homePage.mantle.click()
24+ await page . waitForTimeout ( 10_000 )
25+
26+ const tradePage = new TradeTradePage ( page ) ;
27+ await tradePage . headerConnectWallet . click ( ) ;
28+
29+ const connectWalletPage = new ConnectWalletPage ( page )
30+ await connectWalletPage . selectWallet . isVisible ( )
31+
32+ await connectWalletPage . encryptedKeyBtn . click ( { delay : 2000 } )
33+ const encryptedKeyPage = new EncryptedKeyPage ( page )
34+
35+ await encryptedKeyPage . encryptedKeyTextbox . waitFor ( { state : 'visible' } )
36+ await encryptedKeyPage . encryptedKeyTextbox . click ( )
37+ await encryptedKeyPage . encryptedKeyTextbox . fill ( encryptedLeapKey )
38+ await encryptedKeyPage . encryptedKeyTextbox . press ( 'Tab' )
39+ await encryptedKeyPage . passwordTextbox . fill ( passworld )
40+ await encryptedKeyPage . passwordTextbox . press ( 'Tab' )
41+ await encryptedKeyPage . connectBtn . waitFor ( { state : 'visible' } )
42+ await encryptedKeyPage . connectBtn . click ( { delay : 2000 } )
43+ await encryptedKeyPage . connectBtn . waitFor ( { state : 'detached' } )
44+
45+ await homePage . addressDropBtn . waitFor ( { state : 'visible' } )
46+
47+ } )
48+
49+ test . describe ( 'Trading Token by Encrypted Key' , ( ) => {
50+ test ( 'TC_DEMEX_TO_1: Place a buy order, verify appearance in order book' , async ( ) => {
51+ const homePage = new HomePage ( page )
52+ await homePage . goToHomePage ( )
53+ await page . waitForLoadState ( )
54+
55+ const tradePage = new TradeTradePage ( page )
56+ await tradePage . opTokenOption . click ( )
57+ await tradePage . spotTab . click ( )
58+ await tradePage . searchToken . fill ( 'SWTH / USD' )
59+ await tradePage . swthUSDOption . click ( )
60+ await tradePage . amountToken . fill ( '1000' )
61+ await tradePage . buyBtn . click ( )
62+ await tradePage . confirmBtn . click ( )
63+
64+ await expect ( tradePage . orderPlacedPopup ) . toBeVisible ( { timeout : 10_000 } )
65+
66+ const expectedTableData = [
67+ {
68+ 'Market' : 'SWTH / USD' ,
69+ 'Type' : 'Limit|Buy' ,
70+ 'Filled' : '0 SWTH$0.00' ,
71+ }
72+ ]
73+ await tradePage . verifyTableData ( expectedTableData )
74+
75+ } )
76+
77+ test ( 'TC_DEMEX_TO_4: Cancel an active order and confirm removal' , async ( ) => {
78+ await page . reload ( )
79+ await page . waitForLoadState ( )
80+ const tradePage = new TradeTradePage ( page )
81+ await tradePage . cancelBtn . click ( )
82+
83+ await expect ( tradePage . orderedCancelledPopup ) . toBeVisible ( { timeout : 10_000 } )
84+ } )
85+
86+ test ( 'TC_DEMEX_TO_2: Place a sell order, verify appearance in order book' , async ( ) => {
87+ await page . reload ( )
88+ await page . waitForLoadState ( )
89+ const tradePage = new TradeTradePage ( page )
90+ await tradePage . amountToken . fill ( '1000' )
91+ await tradePage . switchingBtn . click ( )
92+ await tradePage . sellBtn . click ( )
93+ await tradePage . confirmBtn . click ( )
94+
95+ await expect ( tradePage . orderPlacedPopup ) . toBeVisible ( { timeout : 10_000 } )
96+
97+ const expectedTableData = [
98+ {
99+ 'Market' : 'SWTH / USD' ,
100+ 'Type' : 'Limit|Sell' ,
101+ 'Filled' : '0 SWTH$0.00' ,
102+ }
103+ ]
104+ await tradePage . verifyTableData ( expectedTableData )
105+
106+ await tradePage . cancelBtn . click ( )
107+ await expect ( tradePage . orderedCancelledPopup ) . toBeVisible ( { timeout : 10_000 } )
108+
109+ } )
110+
111+ test ( 'TC_DEMEX_TO_3: Test limit and market orders for a range of assets' , async ( ) => {
112+ await page . reload ( )
113+ await page . waitForLoadState ( )
114+ const tradePage = new TradeTradePage ( page )
115+ await tradePage . marketBtn . click ( )
116+ await tradePage . buyBtn . waitFor ( { state : 'visible' } )
117+ await tradePage . amountOnMarket . fill ( '1000' )
118+ await tradePage . buyBtn . click ( )
119+ await tradePage . confirmBtn . click ( )
120+
121+ await expect ( tradePage . tradeExecutedPopup ) . toBeVisible ( { timeout : 10_000 } )
122+
123+ } )
124+ } )
125+
126+ test . afterAll ( 'Reset data' , async ( ) => {
127+ const homePage = new HomePage ( page )
128+ await homePage . goToHomePage ( )
129+ await page . waitForLoadState ( )
130+
131+ const tradePage = new TradeTradePage ( page )
132+ try {
133+ await tradePage . cancelAllBtn . click ( { timeout : 10_000 } )
134+ await tradePage . confirmBtn . click ( )
135+ await expect ( tradePage . orderedCancelledPopup ) . toBeVisible ( { timeout : 10_000 } )
136+ } catch ( e ) { }
137+
138+ } )
0 commit comments