Files
048-the-coockie-factory/docs/wiki/Step-1-Open-The-Game.md
Tirsvad 314f8b4d77 Add wiki in English, Danish and Bahasa Malaysia and the wiki publish workflow
Nine pages per language (home, description, install, one page per
lecture step with its screenshot and what was gained, appendix) plus the
sidebar. Doxygen now runs without warnings. The publish workflow is the
framework template, unchanged.

Task: MIL-005#1
Task: MIL-005#2
Task: MIL-005#3
Task: MIL-005#4
Task: MIL-005#5
Closes #24
Closes #25
Closes #26
Closes #27
Closes #28
2026-10-28 17:03:46 +08:00

32 lines
1.3 KiB
Markdown

# Step 1: open the game
🌐 **English** · [Dansk](Step-1-Open-The-Game-da) · [Bahasa Melayu](Step-1-Open-The-Game-ms)
The bot starts Chrome, loads the game and waits until the language prompt is on the page. Then it picks English, which makes the big cookie playable.
**Screenshot**
![Step 1: open the game](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/048-the-coockie-factory/raw/branch/main/docs/images/step-1-open-game.png)
**Function**
```python
def open_game(game: GamePort) -> None:
game.open_page(GAME_URL)
game.wait_for_element(LANGUAGE_BUTTON_PREFIX + LANGUAGE_CODE)
def select_language(game: GamePort) -> None:
game.click_element(LANGUAGE_BUTTON_PREFIX + LANGUAGE_CODE)
game.wait_for_element(BIG_COOKIE_ID)
```
## What we gained
- **Wait for an element, do not sleep.** `WebDriverWait` returns as soon as the element exists, so the bot is fast when the page is fast and patient when it is slow.
- **Selenium Manager** finds the matching Chrome driver, so there is no manual download.
- **A port keeps Selenium out of the rules.** `open_game` only talks to `GamePort`, so a fake game tests it without a browser.
- **One place for the page's details.** The address and the element ids are in `constants.py`.
Next: [Step 2: click the cookie](Step-2-Click-The-Cookie)