@@ -95,6 +95,199 @@ async function startTest(gridUrl, capabilities, name) {
9595
9696 // navigate to a url
9797 let url = "https://devci.worksonlocal.dev/tests/player-dynamic/#/testbed?manifest=visual-regression-multiple-choice" ;
98+
99+
100+ console . log ( url ) ;
101+ try {
102+ await driver . get ( url ) ;
103+ console . log ( "URL loaded successfully" ) ;
104+
105+ // Wait for the document ready state to be 'complete'
106+ let readyState = '' ;
107+ for ( let i = 0 ; i < 20 ; i ++ ) { // up to 10 seconds
108+ readyState = await driver . executeScript ( 'return document.readyState' ) ;
109+ if ( readyState === 'complete' ) break ;
110+ await driver . sleep ( 500 ) ;
111+ }
112+ console . log ( 'Document readyState:' , readyState ) ;
113+
114+ // Wait for the page to load and add some debugging
115+ await driver . sleep ( 2000 ) ; // Wait 2 seconds for page to load
116+
117+ // Try to find the element and wait for it to be present
118+ const startAssessmentElement = await driver . wait (
119+ webdriver . until . elementLocated ( By . css ( "[data-cy='startAssessment']" ) ) ,
120+ 10000 // Wait up to 10 seconds
121+ ) ;
122+
123+ await startAssessmentElement . click ( ) ;
124+ console . log ( "Clicked startAssessment button" ) ;
125+
126+ // Take screenshot after startAssessment click
127+ console . log ( "taking screenshot after startAssessment click..." ) ;
128+ let config1 = {
129+ screenshotName : "screenshot-1"
130+ } ;
131+ const screenshotResult1 = await driver . executeScript ( "smartui.takeScreenshot" , config1 ) ;
132+ console . log ( "RESPONSE :" , screenshotResult1 ) ;
133+ await driver . sleep ( 25000 ) ; // Wait 25 seconds before checking status
134+ const status1 = await driver . executeScript ( "smartui.fetchScreenshotStatus=screenshot-1" ) ;
135+ console . log ( "Screenshot 1 Status:" , status1 ) ;
136+
137+ // Wait for the second element and click it
138+ const choiceElement = await driver . wait (
139+ webdriver . until . elementLocated ( By . css ( "[data-cy-choice='1']" ) ) ,
140+ 10000 // Wait up to 10 seconds
141+ ) ;
142+ await choiceElement . click ( ) ;
143+ console . log ( "Clicked choice 1 button" ) ;
144+
145+ // Wait for the header element and click it
146+ const headerElement = await driver . wait (
147+ webdriver . until . elementLocated ( By . css ( "[data-cy='header']" ) ) ,
148+ 10000 // Wait up to 10 seconds
149+ ) ;
150+ await headerElement . click ( ) ;
151+ console . log ( "Clicked header element" ) ;
152+
153+ // Take screenshot after header click
154+ console . log ( "taking screenshot after header click..." ) ;
155+ let config2 = {
156+ screenshotName : "screenshot-2"
157+ } ;
158+ const screenshotResult2 = await driver . executeScript ( "smartui.takeScreenshot" , config2 ) ;
159+ console . log ( "RESPONSE :" , screenshotResult2 ) ;
160+ await driver . sleep ( 25000 ) ; // Wait 25 seconds before checking status
161+ const status2 = await driver . executeScript ( "smartui.fetchScreenshotStatus=screenshot-2" ) ;
162+ console . log ( "Screenshot 2 Status:" , status2 ) ;
163+
164+ // Wait for the second choice element and click it
165+ const choice2Element = await driver . wait (
166+ webdriver . until . elementLocated ( By . css ( "[data-cy-choice='2']" ) ) ,
167+ 10000 // Wait up to 10 seconds
168+ ) ;
169+ await choice2Element . click ( ) ;
170+ console . log ( "Clicked choice 2 button" ) ;
171+
172+ // Click on header element again
173+ const headerElement2 = await driver . wait (
174+ webdriver . until . elementLocated ( By . css ( "[data-cy='header']" ) ) ,
175+ 10000 // Wait up to 10 seconds
176+ ) ;
177+ await headerElement2 . click ( ) ;
178+ console . log ( "Clicked header element again" ) ;
179+
180+ // Take screenshot after second header click
181+ console . log ( "taking screenshot after second header click..." ) ;
182+ let config3 = {
183+ screenshotName : "screenshot-3"
184+ } ;
185+ const screenshotResult3 = await driver . executeScript ( "smartui.takeScreenshot" , config3 ) ;
186+ console . log ( "RESPONSE :" , screenshotResult3 ) ;
187+ await driver . sleep ( 25000 ) ; // Wait 25 seconds before checking status
188+ const status3 = await driver . executeScript ( "smartui.fetchScreenshotStatus=screenshot-3" ) ;
189+ console . log ( "Screenshot 3 Status:" , status3 ) ;
190+
191+ // Take additional screenshot after step 5
192+ console . log ( "taking additional screenshot after step 5..." ) ;
193+ let config4 = {
194+ screenshotName : "screenshot-4"
195+ } ;
196+ const screenshotResult4 = await driver . executeScript ( "smartui.takeScreenshot" , config4 ) ;
197+ console . log ( "RESPONSE :" , screenshotResult4 ) ;
198+ await driver . sleep ( 25000 ) ; // Wait 25 seconds before checking status
199+ const status4 = await driver . executeScript ( "smartui.fetchScreenshotStatus=screenshot-4" ) ;
200+ console . log ( "Screenshot 4 Status:" , status4 ) ;
201+
202+ // Wait for the footer next button and click it
203+ const footerNextElement = await driver . wait (
204+ webdriver . until . elementLocated ( By . css ( "[data-cy='footer-next-button']" ) ) ,
205+ 10000 // Wait up to 10 seconds
206+ ) ;
207+ await footerNextElement . click ( ) ;
208+ console . log ( "Clicked footer next button" ) ;
209+
210+ // Wait for the footer back button and click it
211+ const footerBackElement = await driver . wait (
212+ webdriver . until . elementLocated ( By . css ( "[data-cy='footer-back-button']" ) ) ,
213+ 10000 // Wait up to 10 seconds
214+ ) ;
215+ await footerBackElement . click ( ) ;
216+ console . log ( "Clicked footer back button" ) ;
217+
218+ // Click on choice 2 again
219+ const choice2ElementAgain = await driver . wait (
220+ webdriver . until . elementLocated ( By . css ( "[data-cy-choice='2']" ) ) ,
221+ 10000 // Wait up to 10 seconds
222+ ) ;
223+ await choice2ElementAgain . click ( ) ;
224+ console . log ( "Clicked choice 2 button again" ) ;
225+
226+ // Click on header element again
227+ const headerElement3 = await driver . wait (
228+ webdriver . until . elementLocated ( By . css ( "[data-cy='header']" ) ) ,
229+ 10000 // Wait up to 10 seconds
230+ ) ;
231+ await headerElement3 . click ( ) ;
232+ console . log ( "Clicked header element again" ) ;
233+
234+ // Take screenshot after third header click
235+ console . log ( "taking screenshot after third header click..." ) ;
236+ let config5 = {
237+ screenshotName : "screenshot-5"
238+ } ;
239+ const screenshotResult5 = await driver . executeScript ( "smartui.takeScreenshot" , config5 ) ;
240+ console . log ( "RESPONSE :" , screenshotResult5 ) ;
241+ await driver . sleep ( 25000 ) ; // Wait 25 seconds before checking status
242+ const status5 = await driver . executeScript ( "smartui.fetchScreenshotStatus=screenshot-5" ) ;
243+ console . log ( "Screenshot 5 Status:" , status5 ) ;
244+
245+ console . log ( "All test steps completed successfully!" ) ;
246+
247+ // Mark test as passed and quit driver
248+ try {
249+ await driver . executeScript ( "lambda-status=passed" ) ;
250+ console . log ( "Test marked as passed" ) ;
251+ } catch ( statusErr ) {
252+ console . log ( "Could not set lambda status:" , statusErr ) ;
253+ }
254+
255+ // Quit driver with proper error handling
256+ try {
257+ await driver . quit ( ) ;
258+ console . log ( "Driver quit successfully" ) ;
259+ } catch ( quitErr ) {
260+ console . log ( "Driver quit error (this is normal):" , quitErr . message ) ;
261+ }
262+ } catch ( err ) {
263+ error = JSON . stringify ( err ) ;
264+ console . log ( error ) ;
265+ console . log ( "test failed with reason " + err ) ;
266+
267+ // Try to get page source for debugging
268+ try {
269+ const pageSource = await driver . getPageSource ( ) ;
270+ console . log ( "Page source preview:" , pageSource . substring ( 0 , 1000 ) ) ;
271+ } catch ( sourceErr ) {
272+ console . log ( "Could not get page source:" , sourceErr ) ;
273+ }
274+
275+ // Mark test as failed and quit driver with proper error handling
276+ try {
277+ await driver . executeScript ( "lambda-status=failed" ) ;
278+ console . log ( "Test marked as failed" ) ;
279+ } catch ( statusErr ) {
280+ console . log ( "Could not set lambda status:" , statusErr ) ;
281+ }
282+
283+ try {
284+ await driver . quit ( ) ;
285+ console . log ( "Driver quit successfully after error" ) ;
286+ } catch ( quitErr ) {
287+ console . log ( "Driver quit error after failure (this is normal):" , quitErr . message ) ;
288+ }
289+ }
290+
98291 console . log ( url ) ;
99292 await driver
100293 . get ( url )
0 commit comments