test_e2e.py (15854B)
1 from playwright.sync_api import Page, expect 2 3 def test_basic(page: Page): 4 # Start on homepage 5 page.goto('/') 6 7 # Click 'Create a Slideshow' 8 page.get_by_role('link', name='Create a Slideshow').click() 9 expect(page).to_have_url('http://localhost:5002/create/step-1/') 10 11 # Fill in song information 12 page.get_by_placeholder('Song title').last.fill('Song 1') 13 page.get_by_placeholder('Song artist').last.fill('aRtIsT A') 14 page.get_by_role('button', name='Add Song').click() 15 page.get_by_placeholder('Song title').last.fill('Song 5') 16 page.get_by_placeholder('Song artist').last.fill('') 17 18 # Click Next 19 page.get_by_role('button', name='Next').click() 20 expect(page).to_have_url('http://localhost:5002/create/step-2/') 21 22 # Assert missing song message is correct 23 expect(page.get_by_text('Lyrics must be entered manually for 1 song(s).')).to_be_visible() 24 25 # Assert songs are loaded 26 expect(page.get_by_text('Song 1 (Artist A)')).to_be_visible() 27 expect(page.get_by_text('lyrics not found').first).to_be_hidden() 28 expect(page.get_by_text('lyrics not found').last).to_be_visible() 29 expect(page.get_by_text('Song 5 lyrics not found')).to_be_visible() 30 31 # Assert song lyrics are loaded (Song 1 lyrics still collapsed) 32 expect(page.get_by_role('textbox')).to_have_count(1) 33 expect(page.get_by_role('textbox').first).to_have_value('') 34 35 # Uncollapse Song 1 36 page.get_by_text('Song 1 (Artist A)').click() 37 38 # Assert song lyrics are loaded (Song 1 lyrics uncollapsed) 39 expect(page.get_by_role('textbox')).to_have_count(2) 40 expect(page.get_by_role('textbox').first).to_have_value('These are the lyrics\nto song 1\nby artist A') 41 expect(page.get_by_role('textbox').last).to_have_value('') 42 43 # Fill in missing lyrics 44 page.get_by_role('textbox').last.fill('custom song 5 lyrics') 45 46 # Click Next 47 page.get_by_role('button', name='Next').click() 48 expect(page).to_have_url('http://localhost:5002/create/step-3/') 49 50 # Fill in slideshow settings 51 page.get_by_role('checkbox', name='Include a title slide before each song').uncheck() 52 53 # Click create 54 page.get_by_role('button', name='Create').click() 55 expect(page).to_have_url('http://localhost:5002/slides/') 56 57 # Assert slide content is correct 58 expect(page.locator('css=section.present')).to_have_text('THESE ARE THE LYRICS\nTO SONG 1\nBY ARTIST A') 59 page.keyboard.press('ArrowRight') 60 expect(page.locator('css=section.present')).to_have_text('') 61 page.keyboard.press('ArrowRight') 62 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 63 page.keyboard.press('ArrowRight') 64 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 65 66 def test_pptx(page: Page): 67 # Start on homepage 68 page.goto('/') 69 70 # Click 'Create a Slideshow' 71 page.get_by_role('link', name='Create a Slideshow').click() 72 expect(page).to_have_url('http://localhost:5002/create/step-1/') 73 74 # Fill in song information 75 page.get_by_placeholder('Song title').last.fill('Song 1') 76 page.get_by_placeholder('Song artist').last.fill('aRtIsT A') 77 page.get_by_role('button', name='Add Song').click() 78 page.get_by_placeholder('Song title').last.fill('Song 5') 79 page.get_by_placeholder('Song artist').last.fill('') 80 81 # Click Next 82 page.get_by_role('button', name='Next').click() 83 expect(page).to_have_url('http://localhost:5002/create/step-2/') 84 85 # Fill in missing lyrics 86 page.get_by_role('textbox').last.fill('custom song 5 lyrics') 87 88 # Click Next 89 page.get_by_role('button', name='Next').click() 90 expect(page).to_have_url('http://localhost:5002/create/step-3/') 91 92 # Fill in slideshow settings 93 page.get_by_role('checkbox', name='Include a title slide before each song').uncheck() 94 page.get_by_role('radio', name='PowerPoint Download').check() 95 96 # Click create 97 with page.expect_download() as download: 98 page.get_by_role('button', name='Create').click() 99 100 # Assert PowerPoint was downloaded 101 assert download.value.suggested_filename == 'slides.pptx' 102 103 # Assert redirected to post download page 104 expect(page).to_have_url('http://localhost:5002/post-download/') 105 106 def test_localStorage(page: Page): 107 # Start on homepage 108 page.goto('/') 109 110 # Click 'Create a Slideshow' 111 page.get_by_role('link', name='Create a Slideshow').click() 112 expect(page).to_have_url('http://localhost:5002/create/step-1/') 113 114 # Assert song information is not prefilled 115 expect(page.get_by_placeholder('Song title')).to_have_count(1) 116 expect(page.get_by_placeholder('Song title')).to_have_value('') 117 expect(page.get_by_placeholder('Song artist')).to_have_count(1) 118 expect(page.get_by_placeholder('Song artist')).to_have_value('') 119 120 # Fill in song information 121 page.get_by_placeholder('Song title').last.fill('Song 1') 122 page.get_by_placeholder('Song artist').last.fill('aRtIsT A') 123 page.get_by_role('button', name='Add Song').click() 124 page.get_by_placeholder('Song title').last.fill('Song 5') 125 page.get_by_placeholder('Song artist').last.fill('') 126 127 # Click Next 128 page.get_by_role('button', name='Next').click() 129 expect(page).to_have_url('http://localhost:5002/create/step-2/') 130 131 # Update lyrics 132 page.get_by_text('Song 1 (Artist A)').click() 133 page.get_by_role('textbox').first.fill('custom song 1 lyrics') 134 page.get_by_role('textbox').last.fill('custom song 5 lyrics') 135 136 # Click Next 137 page.get_by_role('button', name='Next').click() 138 expect(page).to_have_url('http://localhost:5002/create/step-3/') 139 140 # Assert slideshow settings have default values 141 expect(page.get_by_role('checkbox', name='Include a title slide before each song')).to_be_checked() 142 expect(page.get_by_role('checkbox', name='Include a blank slide between each song')).to_be_checked() 143 expect(page.get_by_role('radio', name='Web View')).to_be_checked() 144 145 # Fill in slideshow settings 146 page.get_by_role('checkbox', name='Include a title slide before each song').uncheck() 147 page.get_by_role('radio', name='PowerPoint Download').check() 148 149 # Click create 150 page.get_by_role('button', name='Create').click() 151 expect(page).to_have_url('http://localhost:5002/post-download/') 152 153 # Return to homepage 154 page.goto('/') 155 156 # Click 'Create a Slideshow' 157 page.get_by_role('link', name='Create a Slideshow').click() 158 expect(page).to_have_url('http://localhost:5002/create/step-1/') 159 160 # Assert song information is prefilled 161 expect(page.get_by_placeholder('Song title')).to_have_count(2) 162 expect(page.get_by_placeholder('Song title').first).to_have_value('Song 1') 163 expect(page.get_by_placeholder('Song title').last).to_have_value('Song 5') 164 expect(page.get_by_placeholder('Song artist')).to_have_count(2) 165 expect(page.get_by_placeholder('Song artist').first).to_have_value('aRtIsT A') 166 expect(page.get_by_placeholder('Song artist').last).to_have_value('') 167 168 # Click Next 169 page.get_by_role('button', name='Next').click() 170 expect(page).to_have_url('http://localhost:5002/create/step-2/') 171 172 # Assert song lyrics are collapsed and not missing 173 expect(page.get_by_role('textbox')).to_have_count(0) 174 expect(page.get_by_text('lyrics not found').first).to_be_hidden() 175 expect(page.get_by_text('lyrics not found').last).to_be_hidden() 176 177 # Uncollapse songs 178 page.get_by_text('Song 1 (Artist A)').click() 179 page.get_by_text('Song 5').click() 180 181 # Assert song lyrics are prefilled 182 expect(page.get_by_role('textbox').first).to_have_value('custom song 1 lyrics') 183 expect(page.get_by_role('textbox').last).to_have_value('custom song 5 lyrics') 184 185 # Click Next 186 page.get_by_role('button', name='Next').click() 187 expect(page).to_have_url('http://localhost:5002/create/step-3/') 188 189 # Assert slideshow settings have custom values 190 expect(page.get_by_role('checkbox', name='Include a title slide before each song')).to_be_checked(checked = False) 191 expect(page.get_by_role('checkbox', name='Include a blank slide between each song')).to_be_checked() 192 193 def test_back(page: Page): 194 # Start on homepage 195 page.goto('/') 196 197 # Click 'Create a Slideshow' 198 page.get_by_role('link', name='Create a Slideshow').click() 199 expect(page).to_have_url('http://localhost:5002/create/step-1/') 200 201 # Fill in bad song information 202 page.get_by_placeholder('Song title').last.fill('Song 11') 203 page.get_by_placeholder('Song artist').last.fill('aRtIsT Aa') 204 page.get_by_role('button', name='Add Song').click() 205 page.get_by_placeholder('Song title').last.fill('Song 55') 206 page.get_by_placeholder('Song artist').last.fill('b') 207 208 # Click Next 209 page.get_by_role('button', name='Next').click() 210 expect(page).to_have_url('http://localhost:5002/create/step-2/') 211 212 # Assert songs are loaded 213 expect(page.get_by_text('Song 11 (Artist Aa) lyrics not found')).to_be_visible() 214 expect(page.get_by_text('Song 5 lyrics not found')).to_be_hidden() 215 216 # Assert song lyrics are loaded 217 expect(page.get_by_role('textbox')).to_have_count(2) 218 expect(page.get_by_role('textbox').first).to_have_value('') 219 expect(page.get_by_role('textbox').last).to_have_value('') 220 221 # Click Back 222 page.get_by_role('button', name='Back').click() 223 expect(page).to_have_url('http://localhost:5002/create/step-1/') 224 225 # Assert bad song information is still present 226 expect(page.get_by_placeholder('Song title')).to_have_count(2) 227 expect(page.get_by_placeholder('Song title').first).to_have_value('Song 11') 228 expect(page.get_by_placeholder('Song title').last).to_have_value('Song 55') 229 expect(page.get_by_placeholder('Song artist')).to_have_count(2) 230 expect(page.get_by_placeholder('Song artist').first).to_have_value('aRtIsT Aa') 231 expect(page.get_by_placeholder('Song artist').last).to_have_value('b') 232 233 # Fill in correct song information 234 page.get_by_placeholder('Song title').last.fill('Song 1') 235 page.get_by_placeholder('Song artist').last.fill('aRtIsT A') 236 page.get_by_role('button', name='Remove').first.click() 237 page.get_by_role('button', name='Add Song').click() 238 page.get_by_placeholder('Song title').last.fill('Song 5') 239 page.get_by_placeholder('Song artist').last.fill('') 240 241 # Click Next 242 page.get_by_role('button', name='Next').click() 243 expect(page).to_have_url('http://localhost:5002/create/step-2/') 244 245 # Assert songs are loaded 246 expect(page.get_by_text('Song 1 (Artist A)')).to_be_visible() 247 expect(page.get_by_text('lyrics not found').first).to_be_hidden() 248 expect(page.get_by_text('lyrics not found').last).to_be_visible() 249 expect(page.get_by_text('Song 5 lyrics not found')).to_be_visible() 250 251 # Uncollapse Song 1 252 page.get_by_text('Song 1 (Artist A)').click() 253 254 # Assert songs lyrics are loaded 255 expect(page.get_by_role('textbox')).to_have_count(2) 256 expect(page.get_by_role('textbox').first).to_have_value('These are the lyrics\nto song 1\nby artist A') 257 expect(page.get_by_role('textbox').last).to_have_value('') 258 259 # Update song lyrics 260 page.get_by_role('textbox').first.fill('custom song 1 lyrics') 261 page.get_by_role('textbox').last.fill('custom song 5 lyrics') 262 263 # Click Next 264 page.get_by_role('button', name='Next').click() 265 expect(page).to_have_url('http://localhost:5002/create/step-3/') 266 267 # Click Back 268 page.get_by_role('button', name='Back').click() 269 expect(page).to_have_url('http://localhost:5002/create/step-2/') 270 271 # Uncollapse songs 272 page.get_by_text('Song 1 (Artist A)').click() 273 page.get_by_text('Song 5').click() 274 275 # Assert updated song lyrics are still loaded 276 expect(page.get_by_role('textbox')).to_have_count(2) 277 expect(page.get_by_role('textbox').first).to_have_value('custom song 1 lyrics') 278 expect(page.get_by_role('textbox').last).to_have_value('custom song 5 lyrics') 279 280 # Revert lyrics 281 page.get_by_title('Revert lyrics').first.click() 282 expect(page.get_by_role('textbox').first).to_have_value('These are the lyrics\nto song 1\nby artist A') 283 page.get_by_title('Revert lyrics').last.click() 284 expect(page.get_by_role('textbox').last).to_have_value('') 285 286 # Fill in correct missing lyrics 287 page.get_by_role('textbox').last.fill('custom song 5 lyrics') 288 289 # Click Next 290 page.get_by_role('button', name='Next').click() 291 expect(page).to_have_url('http://localhost:5002/create/step-3/') 292 293 # Fill in bad slideshow settings 294 page.get_by_role('checkbox', name='Include a blank slide between each song').uncheck() 295 296 # Click create 297 page.get_by_role('button', name='Create').click() 298 expect(page).to_have_url('http://localhost:5002/slides/') 299 300 # Assert slide content is correct 301 expect(page.locator('css=section.present')).to_have_text('SONG 1') 302 page.keyboard.press('ArrowRight') 303 expect(page.locator('css=section.present')).to_have_text('THESE ARE THE LYRICS\nTO SONG 1\nBY ARTIST A') 304 page.keyboard.press('ArrowRight') 305 expect(page.locator('css=section.present')).to_have_text('SONG 5') 306 page.keyboard.press('ArrowRight') 307 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 308 page.keyboard.press('ArrowRight') 309 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 310 311 # Click back 312 page.go_back() 313 expect(page).to_have_url('http://localhost:5002/create/step-3/') 314 315 # Assert bad slideshow settings still loaded 316 expect(page.get_by_role('checkbox', name='Include a blank slide between each song')).to_be_checked(checked = False) 317 expect(page.get_by_role('checkbox', name='Include a title slide before each song')).to_be_checked() 318 319 # Fill in correct slideshow settings 320 page.get_by_role('checkbox', name='Include a title slide before each song').uncheck() 321 322 # Click create 323 page.get_by_role('button', name='Create').click() 324 expect(page).to_have_url('http://localhost:5002/slides/') 325 326 # Assert slide content is correct 327 expect(page.locator('css=section.present')).to_have_text('THESE ARE THE LYRICS\nTO SONG 1\nBY ARTIST A') 328 page.keyboard.press('ArrowRight') 329 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 330 page.keyboard.press('ArrowRight') 331 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 5 LYRICS') 332 333 def test_no_javascript(page: Page): 334 page.java_script_enabled = False 335 336 # Start on homepage 337 page.goto('/') 338 339 # Click 'Create a Slideshow' 340 page.get_by_role('link', name='Create a Slideshow').click() 341 expect(page).to_have_url('http://localhost:5002/create/step-1/') 342 343 # Fill in song information 344 page.get_by_placeholder('Song title').last.fill('Song 1') 345 page.get_by_placeholder('Song artist').last.fill('aRtIsT A') 346 347 # Click Next 348 page.get_by_role('button', name='Next').click() 349 expect(page).to_have_url('http://localhost:5002/create/step-2/') 350 351 # Assert song is loaded 352 expect(page.get_by_text('Song 1 (Artist A)')).to_be_visible() 353 expect(page.get_by_text('lyrics not found')).to_be_hidden() 354 355 # Assert song lyrics are loaded 356 expect(page.get_by_role('textbox')).to_have_value('These are the lyrics\nto song 1\nby artist A') 357 358 # Update lyrics 359 page.get_by_role('textbox').last.fill('custom song 1 lyrics') 360 361 # Click Next 362 page.get_by_role('button', name='Next').click() 363 expect(page).to_have_url('http://localhost:5002/create/step-3/') 364 365 # Fill in slideshow settings 366 page.get_by_role('checkbox', name='Include a title slide before each song').uncheck() 367 368 # Click create 369 page.get_by_role('button', name='Create').click() 370 expect(page).to_have_url('http://localhost:5002/slides/') 371 372 # Assert slide content is correct 373 expect(page.locator('css=section.present')).to_have_text('CUSTOM SONG 1 LYRICS')