-
Notifications
You must be signed in to change notification settings - Fork 0
הוספת לוגין רמי לוי ופונקציונליות חיפוש והוספת מוצר לעגלה בשופרסל #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: exercises
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ __pycache__/ | |
| !*/ | ||
| !*.py | ||
| !.gitignor | ||
|
|
||
| .venv/ | ||
| .env | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from selenium.common.exceptions import TimeoutException | ||
| from core.online_store import OnlineStore | ||
|
|
||
| class BaseStore(OnlineStore): | ||
|
|
||
| # ✅ פונקציית login - מרוכזת אחת בלבד | ||
| def login(self, username, password): | ||
| print(f"🌐 טוען דף: {self.get_login_url()}") | ||
| self.driver.get(self.get_login_url()) | ||
|
|
||
| self.open_login_modal() | ||
|
|
||
| try: | ||
| print("⌛ ממתין לשדות התחברות...") | ||
| self.wait_for_element(self.get_username_selector()) | ||
| self.fill_input(self.get_username_selector(), username) | ||
| self.fill_input(self.get_password_selector(), password) | ||
|
|
||
| self.wait_and_click(self.get_submit_selector()) | ||
|
|
||
| # self.wait_until_disappear(self.get_username_selector()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. האם מדובר בלוגין לאתר מסוים או לוגין כללי? |
||
| self.wait_for_element("div#user-box") | ||
| print("✅ התחברות הצליחה") | ||
|
|
||
|
|
||
| except TimeoutException: | ||
| raise Exception("❌ שגיאה בהתחברות") | ||
|
|
||
| # ✅ פונקציית ברירת מחדל לפתיחת מודל התחברות | ||
| def open_login_modal(self): | ||
| pass | ||
|
|
||
| # ✅ פונקציות עזר כלליות לשימוש חוזר בכל תהליך (לא רק login) | ||
| def wait_for_element(self, selector, timeout=10): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. הפונקציות הכלליות מצוינות. |
||
| return WebDriverWait(self.driver, timeout).until( | ||
| EC.presence_of_element_located((By.CSS_SELECTOR, selector)) | ||
| ) | ||
|
|
||
| def wait_and_click(self, selector, timeout=10): | ||
| WebDriverWait(self.driver, timeout).until( | ||
| EC.element_to_be_clickable((By.CSS_SELECTOR, selector)) | ||
| ).click() | ||
|
|
||
| def fill_input(self, selector, value): | ||
| self.driver.find_element(By.CSS_SELECTOR, selector).send_keys(value) | ||
|
|
||
| def wait_until_disappear(self, selector, timeout=10): | ||
| WebDriverWait(self.driver, timeout).until_not( | ||
| EC.presence_of_element_located((By.CSS_SELECTOR, selector)) | ||
| ) | ||
|
|
||
| # ✅ פונקציות מופשטות שהמחלקות היורשות חייבות לממש | ||
| def get_login_url(self): | ||
| raise NotImplementedError | ||
|
|
||
| def get_username_selector(self): | ||
| raise NotImplementedError | ||
|
|
||
| def get_password_selector(self): | ||
| raise NotImplementedError | ||
|
|
||
| def get_submit_selector(self): | ||
| raise NotImplementedError | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| class OnlineStore: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. מדובר בabstract class, תוסיפי לשם של הclass ירושה בABC |
||
| def __init__(self, driver): | ||
| self.driver = driver | ||
|
|
||
| def login(self, username, password): | ||
| raise NotImplementedError | ||
|
|
||
| def search_item(self, item_name): | ||
| raise NotImplementedError | ||
|
|
||
| def add_to_cart(self, item_name): | ||
| raise NotImplementedError | ||
|
|
||
| def checkout(self): | ||
| raise NotImplementedError | ||
| # | ||
| # from abc import ABC, abstractmethod | ||
| # | ||
| # class OnlineStore(ABC): | ||
| # def __init__(self, driver): | ||
| # self.driver = driver | ||
| # | ||
| # @abstractmethod | ||
| # def login(self, username, password): | ||
| # pass | ||
| # | ||
| # @abstractmethod | ||
| # def search_item(self, item_name): | ||
| # pass | ||
| # | ||
| # @abstractmethod | ||
| # def add_to_cart(self, item_name): | ||
| # pass | ||
| # | ||
| # @abstractmethod | ||
| # def checkout(self): | ||
| # pass | ||
|
|
||
|
|
||
|
|
||
| # דוגמא לקוד ששני הביאה | ||
| # | ||
| # class StoreA(OnlineStore): | ||
| # def login(self, username, password): | ||
| # self.driver.get("https://store-a.com/login") | ||
| # WebDriverWait(self.driver, 10).until( | ||
| # EC.presence_of_element_located((By.ID, "username")) | ||
| # ).send_keys(username) | ||
| # self.driver.find_element(By.ID, "password").send_keys(password) | ||
| # self.driver.find_element(By.ID, "login-button").click() | ||
| # | ||
| # def search_item(self, item_name): | ||
| # search_box = WebDriverWait(self.driver, 10).until( | ||
| # EC.presence_of_element_located((By.ID, "search-box")) | ||
| # ) | ||
| # search_box.send_keys(item_name) | ||
| # search_box.submit() | ||
| # | ||
| # def add_to_cart(self, item_name): | ||
| # self.search_item(item_name) | ||
| # WebDriverWait(self.driver, 10).until( | ||
| # EC.presence_of_element_located((By.CLASS_NAME, "add-to-cart")) | ||
| # ).click() | ||
| # | ||
| # def checkout(self): | ||
| # self.driver.get("https://store-a.com/cart") | ||
| # WebDriverWait(self.driver, 10).until( | ||
| # EC.presence_of_element_located((By.ID, "checkout-button")) | ||
| # ).click() | ||
| # | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
תעוד לקוד אמור להיות בעברית