-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (44 loc) · 1.64 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pages.AmazonPage import AmazonPage
from pages.EbayPage import EbayPage
from selenium import webdriver
def setup (browser):
if browser.lower() == "chrome":
driver = webdriver.Chrome("./resources/chromedriver.exe")
elif browser.lower() == "firefox":
driver = webdriver.Firefox(executable_path="./resources/geckodriver.exe")
else:
raise Exception("{} Browser is not supported".format(browser))
#Implicit wait
driver.implicitly_wait(3)
#driver.maximize_windows()
return driver
def teardown(driver):
driver.quit()
def sort_combined_result(results):
results.sort(key=getPrice)
return results
def getPrice(list_content):
#return price
return list_content[2]
if __name__ == "__main__":
driver = setup("chrome")
amazon_page = AmazonPage(driver)
amazon_page.load_page()
#need to change currency to MYR since amazon price in USD.
amazon_page.change_currency_to_myr()
amazon_page.search_item("iPhone 11")
#get the list of the result that have been verified is iphone11 related
amazon_results = amazon_page.get_searchresult()
ebay_page = EbayPage(driver)
ebay_page.load_page()
ebay_page.search_item("iPhone 11")
#get the list of the result that have been verified is iphone11 related
ebay_results = ebay_page.get_searchresult()
all_results = amazon_results + ebay_results
sorted_results = sort_combined_result(all_results)
#use for debugging - see the price is sorted ascending order
for item in sorted_results:
print(item[2])
for item in sorted_results:
print(item)
teardown(driver)