Coverage for src / ocarina / opinionated / dsl / drive_page.py: 75.00%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-06-04 16:22 +0200

1"""Chain actions over a page. 

2 

3Example: 

4 >>> def test_scenario( 

5 ... driver: WebDriver, 

6 ... logger: ILogger 

7 ... ) -> TestChain: 

8 ... return [ 

9 ... drive_page( 

10 ... act(login_page, open_login_page) 

11 ... .failure(log_error("Failed to open login page")) 

12 ... .success(log_success("Login page opened")), 

13 ... act(login_page, enter_credentials) 

14 ... .failure(log_error("Failed to enter credentials")) 

15 ... .success(log_success("Credentials entered")) 

16 ... ), 

17 ... drive_page( 

18 ... act(welcome_page, verify_welcome_page) 

19 ... .failure(log_error("Welcome page not found")) 

20 ... .success(log_success("Welcome page verified")) 

21 ... ) 

22 ... ] 

23 

24""" 

25 

26from typing import TYPE_CHECKING 

27 

28from ocarina.dsl.testing_with_railway.chain_actions import ChainRunner, chain_actions 

29 

30if TYPE_CHECKING: 

31 from ocarina.custom_types.tpom import TPOM 

32 from ocarina.dsl.testing_with_railway.internals.action_chain import ActionSuccess 

33 

34 

35def drive_page( 

36 first: ActionSuccess[TPOM], *rest: ActionSuccess[TPOM] 

37) -> ChainRunner[TPOM]: 

38 """Chain actions over a page. 

39 

40 Example: 

41 >>> def test_scenario( 

42 ... driver: WebDriver, 

43 ... logger: ILogger 

44 ... ) -> Sequence[ChainRunner[Any]]: 

45 ... return [ 

46 ... drive_page( 

47 ... act(login_page, open_login_page) 

48 ... .failure(log_error("Failed to open login page")) 

49 ... .success(log_success("Login page opened")), 

50 ... act(login_page, enter_credentials) 

51 ... .failure(log_error("Failed to enter credentials")) 

52 ... .success(log_success("Credentials entered")) 

53 ... ), 

54 ... drive_page( 

55 ... act(welcome_page, verify_welcome_page) 

56 ... .failure(log_error("Welcome page not found")) 

57 ... .success(log_success("Welcome page verified")) 

58 ... ) 

59 ... ] 

60 

61 """ 

62 return chain_actions(first, *rest)