Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ __pycache__/
!*/
!*.py
!.gitignor

.venv/
.env
2 changes: 1 addition & 1 deletion .idea/food_scraper_project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions core/base_store.py
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 - מרוכזת אחת בלבד

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

תעוד לקוד אמור להיות בעברית

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())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

האם מדובר בלוגין לאתר מסוים או לוגין כללי?
כי אם מדובר בלוגין כללי div#user-box מתכוון לID ספציפי, ואם מדובר בלוגין ספציפי - למה הוא ממומש בקלאס הזה?

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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

הפונקציות הכלליות מצוינות.
הייתי ממליצה להפריד אותן לclass אחר סטטי (יקראו לו לדוגמא SeleniumAction)

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
70 changes: 70 additions & 0 deletions core/online_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class OnlineStore:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

מדובר בabstract class, תוסיפי לשם של הclass ירושה בABC
ובכל הפונקציות תכתבי pass במקום raise NotImplementedError

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()
#
Loading