-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
__init__.py
89 lines (58 loc) · 3 KB
/
__init__.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
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as Condition
def getShowDashboardButton(browser):
return browser.find_element_by_id("btn-show-dashboard")
def get(browser):
""" Return the dashboard WebElement """
return browser.find_element_by_id("main-dashboard-modal")
def open(browser):
"""Open the dashboard and wait until displayed"""
WebDriverWait(browser, 10).until(Condition.visibility_of_element_located((By.ID, "btn-show-dashboard")))
getShowDashboardButton(browser).click()
WebDriverWait(browser, 10).until(Condition.visibility_of_element_located((By.ID, "main-dashboard-modal")))
return get(browser)
def close(browser):
"""Close the dashboard"""
browser.find_element_by_xpath(".//div[@id='main-dashboard-modal']//div[@class='modal-footer']//button[@data-i18n='common.close']").click();
waitForClosed(browser)
def waitForClosed(browser):
return WebDriverWait(browser, 10).until(Condition.invisibility_of_element_located((By.ID, "main-dashboard-modal")))
def openPage(browser, pageElementId, elementIdToWait):
"""Open a specific dashboard page"""
# Note that the navigation is not perfect, but considered as acceptable for actual Yadoms version
# See testNavigationAccrossPages.py and https://github.com/Yadoms/yadoms/issues/172 for more information
# So the ideal code should be :
#
#browser.find_element_by_id(pageElementId).click()
#WebDriverWait(browser, 10).until(Condition.visibility_of_element_located((By.ID, elementIdToWait)))
#
# But here we don't want to be blocked here, so this is a workaround :
import time
button = browser.find_element_by_id(pageElementId)
retries = 10
while(retries > 0):
button.click()
time.sleep(1)
foundElements = browser.find_elements_by_xpath(".//div[@id='main-dashboard-sub-window-content']//*[@id='" + elementIdToWait + "']")
if len(foundElements) and foundElements[0].is_displayed():
return
retries = retries - 1
assert False
def openSummary(browser):
"""Open the summary page of dashboard"""
openPage(browser, "btn-dashboard-summary", "dashboard-summary")
def openSystemConfiguration(browser):
"""Open the system configuration page of dashboard"""
openPage(browser, "btn-dashboard-system-configuration", "dashboard-system-configuration")
def openAutomation(browser):
"""Open the automation page of dashboard"""
openPage(browser, "btn-dashboard-automatisation", "automation-rule-list")
def openPlugin(browser):
"""Open the plugin page of dashboard"""
openPage(browser, "btn-dashboard-plugins", "plugin-instance-list")
def openDevice(browser):
"""Open the device page of dashboard"""
openPage(browser, "btn-dashboard-devices", "device-list")