-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_reader_page.py
116 lines (94 loc) · 4.44 KB
/
google_reader_page.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'''
Created on 03.08.2012
@author: avkoltsov
'''
from google_reader_selectors import GoogleReaderSelectors
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from datetime import datetime
WAIT_FOR_SUBSCRIPTION_LOAD = 3
class GoogleReaderPage(object):
def __init__(self, driver):
self.driver = driver
def open_page(self):
self.driver.get('https://www.google.com/reader/')
def get_element(self, locator):
'''
throws exception if element not found
'''
selector_type , selector = locator.split('=', 1)
element = None
if 'id' == selector_type:
element = self.driver.find_element(by=By.ID, value=selector)
elif 'xpath' == selector_type:
element = self.driver.find_element(by=By.XPATH, value=selector)
elif 'link_text' == selector_type:
element = self.driver.find_element(by=By.LINK_TEXT, value=selector)
elif 'partial_link_text' == selector_type:
element = self.driver.find_element(by=By.PARTIAL_LINK_TEXT, value=selector)
elif 'name' == selector_type:
element = self.driver.find_element(by=By.NAME, value=selector)
elif 'tag' == selector_type:
element = self.driver.find_element(by=By.TAG_NAME, value=selector)
elif 'class' == selector_type:
element = self.driver.find_element(by=By.CLASS_NAME, value=selector)
elif 'css' == selector_type:
element = self.driver.find_element(by=By.CSS_SELECTOR, value=selector)
return element
def get_elements(self, locator):
selector_type , selector = locator.split('=', 1)
elements = []
if 'id' == selector_type:
elements = self.driver.find_elements(by=By.ID, value=selector)
elif 'xpath' == selector_type:
elements = self.driver.find_elements(by=By.XPATH, value=selector)
elif 'link_text' == selector_type:
elements = self.driver.find_elements(by=By.LINK_TEXT, value=selector)
elif 'partial_link_text' == selector_type:
elements = self.driver.find_elements(by=By.PARTIAL_LINK_TEXT, value=selector)
elif 'name' == selector_type:
elements = self.driver.find_elements(by=By.NAME, value=selector)
elif 'tag' == selector_type:
elements = self.driver.find_elements(by=By.TAG_NAME, value=selector)
elif 'class' == selector_type:
elements = self.driver.find_elements(by=By.CLASS_NAME, value=selector)
elif 'css' == selector_type:
elements = self.driver.find_elements(by=By.CSS_SELECTOR, value=selector)
return elements
def get_subscriptions(self):
return self.get_elements(GoogleReaderSelectors.subscriptions)
def get_entries(self):
return self.get_elements(GoogleReaderSelectors.entries)
def open_subscription(self, webelement):
webelement.click()
webelement.click()
self.wait_spinner_is_visible()
def scroll_entries_down(self):
last = self.get_entries()[-1]
while True:
body = self.get_element('tag=body')
body.send_keys(Keys.PAGE_DOWN)
self.wait_spinner_is_visible()
new_last = self.get_entries()[-1]
if last._id == new_last._id:
break
last = new_last
def get_date(self, entry):
date_as_str = entry.find_element_by_class_name('entry-date').text
entry_date = None
try:
entry_date = datetime.strptime(date_as_str, '%d.%m.%Y').date()
except:
entry_date = datetime.now().date()
return entry_date
def wait_spinner_is_visible(self, time_to_wait = WAIT_FOR_SUBSCRIPTION_LOAD):
try:
WebDriverWait(self.driver, time_to_wait).\
until(lambda x: self.get_element(GoogleReaderSelectors.spinner).is_displayed(),
'subscrption load too long, more then %s seconds' % time_to_wait)
WebDriverWait(self.driver, time_to_wait).\
until(lambda x: not self.get_element(GoogleReaderSelectors.spinner).is_displayed(),
'subscrption load too long, more then %s seconds' % time_to_wait)
except:
pass