Test calling javascript functions from python. Args: call_script: harness for CallScript app. driver: WebDriver instance. script: The type of script to test.
(
call_script: AppHarness,
driver: WebDriver,
script: str,
)
| 414 | |
| 415 | @pytest.mark.parametrize("script", ["inline", "external"]) |
| 416 | def test_call_script( |
| 417 | call_script: AppHarness, |
| 418 | driver: WebDriver, |
| 419 | script: str, |
| 420 | ): |
| 421 | """Test calling javascript functions from python. |
| 422 | |
| 423 | Args: |
| 424 | call_script: harness for CallScript app. |
| 425 | driver: WebDriver instance. |
| 426 | script: The type of script to test. |
| 427 | """ |
| 428 | assert_token(driver) |
| 429 | reset_button = driver.find_element(By.ID, "reset") |
| 430 | update_counter_button = driver.find_element(By.ID, f"update_{script}_counter") |
| 431 | counter = driver.find_element(By.ID, f"{script}_counter") |
| 432 | results = driver.find_element(By.ID, "results") |
| 433 | yield_button = driver.find_element(By.ID, f"{script}_yield") |
| 434 | return_button = driver.find_element(By.ID, f"{script}_return") |
| 435 | yield_callback_button = driver.find_element(By.ID, f"{script}_yield_callback") |
| 436 | return_callback_button = driver.find_element(By.ID, f"{script}_return_callback") |
| 437 | return_lambda_button = driver.find_element(By.ID, f"{script}_return_lambda") |
| 438 | |
| 439 | yield_button.click() |
| 440 | update_counter_button.click() |
| 441 | assert call_script.poll_for_value(counter, exp_not_equal="0") == "4" |
| 442 | reset_button.click() |
| 443 | assert call_script.poll_for_value(counter, exp_not_equal="4") == "0" |
| 444 | return_button.click() |
| 445 | update_counter_button.click() |
| 446 | assert call_script.poll_for_value(counter, exp_not_equal="0") == "1" |
| 447 | reset_button.click() |
| 448 | assert call_script.poll_for_value(counter, exp_not_equal="1") == "0" |
| 449 | |
| 450 | yield_callback_button.click() |
| 451 | update_counter_button.click() |
| 452 | assert call_script.poll_for_value(counter, exp_not_equal="0") == "4" |
| 453 | assert ( |
| 454 | call_script.poll_for_value(results, exp_not_equal="[]") |
| 455 | == f'["{script}1",null,{{"{script}3":42,"a":[1,2,3],"s":"js","o":{{"a":1,"b":2}}}},"async {script}4"]' |
| 456 | ) |
| 457 | reset_button.click() |
| 458 | assert call_script.poll_for_value(counter, exp_not_equal="4") == "0" |
| 459 | |
| 460 | return_callback_button.click() |
| 461 | update_counter_button.click() |
| 462 | assert call_script.poll_for_value(counter, exp_not_equal="0") == "1" |
| 463 | assert ( |
| 464 | call_script.poll_for_value(results, exp_not_equal="[]") |
| 465 | == f'[{{"{script}3":42,"a":[1,2,3],"s":"js","o":{{"a":1,"b":2}}}}]' |
| 466 | ) |
| 467 | reset_button.click() |
| 468 | assert call_script.poll_for_value(counter, exp_not_equal="1") == "0" |
| 469 | |
| 470 | return_lambda_button.click() |
| 471 | update_counter_button.click() |
| 472 | assert call_script.poll_for_value(counter, exp_not_equal="0") == "1" |
| 473 | assert ( |
nothing calls this directly
no test coverage detected