99@pytest .fixture (scope = "session" )
1010def browser ():
1111 with sync_playwright () as p :
12- # Launch browser in headed mode for debugging
13- browser = p .chromium .launch (headless = False , slow_mo = 1000 )
12+ browser = p .chromium .launch (headless = True , slow_mo = 1000 )
1413 yield browser
1514 browser .close ()
1615
@@ -23,22 +22,18 @@ def page(browser):
2322
2423@pytest .fixture (scope = "session" )
2524def app_url ():
26- # Use boto3 to get the CloudFront distribution ID
2725 cloudfront = boto3 .client ('cloudfront' , endpoint_url = 'http://localhost:4566' )
2826 response = cloudfront .list_distributions ()
2927 distribution_id = response ['DistributionList' ]['Items' ][0 ]['Id' ]
3028 return f"https://{ distribution_id } .cloudfront.localhost.localstack.cloud"
3129
3230def test_quiz_flow (page , app_url ):
3331 # Enable verbose logging
34- page .set_viewport_size ({"width" : 1280 , "height" : 720 })
35-
36- # Navigate to the home page
32+ # page.set_viewport_size({"width": 1280, "height": 720})
33+
34+ # Navigate to home page
3735 print ("\n Navigating to home page..." )
3836 page .goto (app_url )
39-
40- # Verify the home page loaded
41- print ("Verifying home page..." )
4237 expect (page .get_by_text ("Welcome" )).to_be_visible ()
4338
4439 # Select AWS Quiz from public quizzes
@@ -55,8 +50,6 @@ def test_quiz_flow(page, app_url):
5550 print ("Filling in user details..." )
5651 username_input = page .get_by_label ("Username" )
5752 username_input .fill (username )
58-
59- # Optional: Fill in email
6053 email_input = page .get_by_label ("Email (Optional)" )
6154 email_input .fill (email )
6255
@@ -90,41 +83,8 @@ def test_quiz_flow(page, app_url):
9083 answer_radio .click ()
9184
9285 # Wait for next question or submit button
93- time .sleep (2 ) # Increased delay to ensure state updates
94-
95- # After last question, verify we're on the results page
96- print ("Waiting for results page..." )
97-
98- # Take a screenshot for debugging
99- page .screenshot (path = "results-page.png" )
100-
101- # Print current page content for debugging
102- print ("\n Page content after quiz completion:" )
103- print (page .content ())
104-
105- # Try different selectors for the results
106- selectors = [
107- "text=Processing your submission..." ,
108- "text=Your Score" ,
109- "text=Quiz Results" ,
110- ".main-quiz-container" , # Try container class
111- "[data-testid=results-page]" # Try test ID if available
112- ]
113-
114- for selector in selectors :
115- try :
116- print (f"\n Trying to find: { selector } " )
117- element = page .wait_for_selector (selector , timeout = 5000 )
118- if element :
119- print (f"Found element with selector: { selector } " )
120- break
121- except Exception as e :
122- print (f"Selector { selector } not found: { str (e )} " )
123-
124- # Wait longer for results processing
125- print ("Waiting for results to process..." )
126- time .sleep (5 ) # Give more time for backend processing
127-
86+ time .sleep (2 )
87+
12888 # Try to find score text with a more flexible approach
12989 score_element = page .get_by_text ("Score" , exact = False )
13090 if score_element :
@@ -158,6 +118,7 @@ def test_quiz_flow(page, app_url):
158118
159119def test_quiz_creation (page , app_url ):
160120 print ("\n Starting quiz creation test..." )
121+
161122 # Navigate to home page
162123 print ("Navigating to home page..." )
163124 page .goto (app_url )
@@ -189,7 +150,7 @@ def test_quiz_creation(page, app_url):
189150 option_input = page .get_by_role ("textbox" , name = f"Option { i + 1 } " )
190151 option_input .fill (option )
191152
192- # Add trivia (if required)
153+ # Add trivia
193154 print ("Adding trivia..." )
194155 trivia_input = page .get_by_role ("textbox" , name = "Trivia" )
195156 trivia_input .fill ("LocalStack is a cloud service emulator that runs in a single container on your laptop." )
0 commit comments