Skip to content

Commit b809242

Browse files
amazon select category and serach in the serach bar
1 parent 7ffb468 commit b809242

File tree

13 files changed

+114
-77
lines changed

13 files changed

+114
-77
lines changed

Data/TestData/amazon.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
url: https://www.amazon.in/
2+
category: Books
3+
search_text: artificial intelligence

Data/TestData/google.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

Library/locator.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from selenium.webdriver import ActionChains
22
import selenium.webdriver.support.ui as ui
3+
from selenium.webdriver.support.ui import Select
34
from selenium.webdriver.remote import webelement
45
from Library.store import Store
56

@@ -22,7 +23,7 @@ def send_keys(self, string) -> bool:
2223

2324
def click(self) -> bool:
2425
try:
25-
Store.current_driver.find_element(self.by, self.value).click
26+
Store.current_driver.find_element(self.by, self.value).click()
2627
except Exception as e:
2728
print("click not worked at \n" + self.by + "\n" + self.value + "\n Exception: \n" + str(e))
2829
return False
@@ -49,6 +50,10 @@ def text(self) -> str:
4950
else:
5051
return txt_value
5152

53+
def select(self, string):
54+
select = Select(Store.current_driver.find_element(self.by, self.value))
55+
select.select_by_visible_text(string)
56+
5257
def get_attribute(self, name) -> str:
5358
try:
5459
att_value = Store.current_driver.find_element(self.by, self.value).get_attribute(name)
@@ -92,6 +97,14 @@ def is_displayed_with_wait(self, timeout=10) -> bool:
9297
print("is_displayed_with_wait not worked at \n" + self.by + "\n" + self.value + "\n Exception: \n" + str(e))
9398
return False
9499

100+
def wait_till_displayed(self, timeout=10) -> bool:
101+
try:
102+
wait = ui.WebDriverWait(Store.current_driver, timeout)
103+
return wait.until(lambda element: Store.current_driver.find_element(self.by, self.value).is_displayed())
104+
except Exception as e:
105+
print("wait_till_displayed not worked at \n" + self.by + "\n" + self.value + "\n Exception: \n" + str(e))
106+
return False
107+
95108
def click_if_displayed(self) -> bool:
96109
try:
97110
self.is_displayed_with_wait()
@@ -144,11 +157,14 @@ def get_element(self) -> webelement.WebElement:
144157

145158
def clear_and_send_keys(self, string) -> bool:
146159
try:
147-
var = Store.current_driver.find_element(self.by, self.value).clear
160+
var = Store.current_driver.find_element(self.by, self.value).clear()
148161
print("Clear action completed on: " + self.by + " and " + self.value + " Return value is: " + var)
149162
Store.current_driver.find_element(self.by, self.value).send_keys(string)
150163
except Exception as e:
151164
print("Clear and Send keys not worked at \n" + self.by + "\n" + self.value + "\n Exception: \n" + str(e))
152165
return False
153166
else:
154167
return True
168+
169+
def get(self):
170+
return "By: " + self.by + " Value: " + self.value

Library/store.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33

44
class Store:
5-
drivers = []
6-
current_driver = None
5+
drivers = []
6+
current_driver = None
77

8-
def __init__(self):
9-
print("Storing the driver values")
8+
@classmethod
9+
def push(self, driver: webdriver) -> webdriver:
10+
self.drivers.append(driver)
11+
self.set_current_driver(driver)
1012

11-
@classmethod
12-
def push(self, driver: webdriver) -> webdriver:
13-
self.drivers.append(driver)
14-
self.set_current_driver(driver)
13+
@classmethod
14+
def set_current_driver(self, driver: webdriver) -> webdriver:
15+
self.current_driver = driver
1516

16-
@classmethod
17-
def set_current_driver(self, driver: webdriver) -> webdriver:
18-
self.current_driver = driver
19-
20-
@classmethod
21-
def switch_driver(self, driver) -> webdriver:
22-
self.current_driver = driver
17+
@classmethod
18+
def switch_driver(self, driver) -> webdriver:
19+
self.current_driver = driver

Library/variable.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
class Var:
77
file_name = None
8-
local_variable = None
8+
static_variable = None
99
dynamic_variable = None
1010
file_path = None
1111

1212
def __init__(self, file_name, type):
1313
self.file_name = file_name
14-
if type == "local":
14+
if type == "static":
1515
try:
1616
root_dir = os.path.dirname(os.path.abspath(__file__)).replace("/Library", "")
1717
self.file_path = root_dir + '/Data/TestData/' + file_name
1818
with open(self.file_path) as file:
19-
self.local_variable = yaml.load(file, Loader=yaml.FullLoader)
19+
self.static_variable = yaml.load(file, Loader=yaml.FullLoader)
2020
allure.attach.file(self.file_path, name=self.file_name, attachment_type=allure.attachment_type.TEXT)
2121
except Exception as e:
2222
print(e)
@@ -55,9 +55,9 @@ def glob(string):
5555
print(e)
5656
return "None"
5757

58-
def local_value_for(self, string) -> str:
58+
def static_value_for(self, string) -> str:
5959
try:
60-
return self.local_variable[string]
60+
return self.static_variable[string]
6161
except Exception as e:
6262
print(e)
6363
return ""

Locators/amazon_home_page.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from Library.locator import Locator
2+
3+
4+
class AmazonHomePageLocator:
5+
amazon_logo = Locator("css selector", "div#nav-logo a[aria-label='Amazon']")
6+
amazon_search_categories = Locator("css selector", "div.nav-search-scope select.nav-search-dropdown")
7+
amazon_search_categories_text = Locator("css selector", "div.nav-search-facade span")
8+
amazon_search_textbox = Locator("css selector", "div.nav-search-field input.nav-input")
9+
10+
def __init__(self):
11+
print("Locators for google page")
12+
13+
@staticmethod
14+
def amazon_search_category_list(string):
15+
amazon_search_category_list = Locator("xpath", "//select[contains(@class,'nav-search-dropdown')]//option[text("
16+
")='%s']" % string)
17+
return amazon_search_category_list

Locators/google.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

Pages/amazon_home_page.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from Locators.amazon_home_page import AmazonHomePageLocator
2+
3+
4+
class AmazonHomePage(AmazonHomePageLocator):
5+
6+
def __init__(self):
7+
super().__init__()
8+
9+
@classmethod
10+
def is_home_page_displayed(cls):
11+
return AmazonHomePageLocator.amazon_logo.is_displayed_with_wait()
12+
13+
@classmethod
14+
def select_category_drop_down(cls, string):
15+
AmazonHomePageLocator.amazon_search_categories.wait_till_displayed()
16+
AmazonHomePageLocator.amazon_search_categories.select(string)
17+
18+
@classmethod
19+
def get_selected_category(cls):
20+
return AmazonHomePageLocator.amazon_search_categories_text.text()
21+
22+
@classmethod
23+
def search_in_the_search_box(cls,string):
24+
AmazonHomePageLocator.amazon_search_textbox.send_keys(string)

Pages/google.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)