Skip to content

Commit

Permalink
removed more time.sleep() and replaced with WebDriverWait().until()
Browse files Browse the repository at this point in the history
  • Loading branch information
Muryanto authored and Muryanto committed Oct 8, 2018
1 parent 0b42d85 commit db75809
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 47 deletions.
1 change: 1 addition & 0 deletions frontend/tests/lib/BasePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class BasePage(object):
""" All page objects inherit from this """

_wait_timeout = 10
_delay = 3

def __init__(self, driver):
self._validate_page(driver)
Expand Down
47 changes: 8 additions & 39 deletions frontend/tests/lib/MainPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def find_variable(self, var):
'''
var_locator = "//ul[@id='var-list']//a[text() = \"{t}\"]".format(t=var)

#var_locator = "//ul[@id='var-list']//li[@class='active']//a[contains(text() = \"{t}\")]".format(t=var)
#var_locator = '//div[@class="left-size-list"]//div[@class="scroll-area"]//ul[@id="var-list"]//li[@class="active"]'
return self.driver.find_element_by_xpath(var_locator)


Expand All @@ -65,50 +63,21 @@ def delete_variable(self, var):
var_delete_element = self.driver.find_element_by_xpath(self._var_delete_locator)
var_delete_element.click()

def plot_variablePREV(self, var, index):
# REVISIT, should take an argument to plot in which plot area.

print("...click on the variable {v} on main page".format(v=var))
var_element = self.find_variable(var)
var_element.click()
print("...sleep for 3 seconds...")
time.sleep(3)
variable_plot_locator = "//div[@class='plotter-plots']//div[@data-plot-index='{i}']".format(i=index)
plot_area_element = self.driver.find_element_by_xpath(variable_plot_locator)
plot_area_element.click()
print("...drag the variable to the plot area...")
# WORKS - my mouse has to be on the plot area
ActionChains(self.driver).drag_and_drop(var_element, plot_area_element).perform()
#ActionChains(self.driver).drag_and_drop_by_offset(var_element, 2, -1).perform()

# WORKS - my mouse has to be on the plot area
#ActionChains(self.driver).click_and_hold(var_element).move_by_offset(10, -10).release().perform()
print("...sleep for 10 seconds...")
time.sleep(10)


def plot_variable(self, var, index):
# REVISIT, should take an argument to plot in which plot area.

print("...click on the variable {v} on main page".format(v=var))
var_element = self.find_variable(var)
var_element.click()
print("...sleep for 3 seconds...")
time.sleep(3)

variable_plot_locator = "//div[@class='plotter-plots']//div[@data-plot-index='{i}']".format(i=index)
plot_area_element = self.driver.find_element_by_xpath(variable_plot_locator)
plot_area_element.click()
print("...drag the variable to the plot area...")
# WORKS - my mouse has to be on the plot area
#ActionChains(self.driver).drag_and_drop(var_element, plot_area_element).perform()

# WORKS - my mouse has to be on the plot area
#ActionChains(self.driver).click_and_hold(var_element).move_by_offset(10, -10).release().perform()


#ActionChains(self.driver).click_and_hold(var_element).move_to_element(plot_area_element).click(plot_area_element).release().perform()
#ActionChains(self.driver).click_and_hold(var_element).move_to_element(plot_area_element).click_and_hold(plot_area_element).release().perform()
ActionChains(self.driver).move_to_element_with_offset(plot_area_element, 0, 0).click(plot_area_element).perform()
ActionChains(self.driver).click_and_hold(var_element).move_to_element_with_offset(plot_area_element, 0, 0).release().perform()
print("...sleep for 5 seconds...")
time.sleep(5)
ActionChains(self.driver).click_and_hold(var_element).move_to_element(plot_area_element).release().perform()

# wait till canvas is visible
canvas_index_locator = "//div[@id='canvas_{i}_{i}_{i}']".format(i=index)
print("xxx xxx canvas_index_locator: {}".format(canvas_index_locator))
canvas_el = WebDriverWait(self.driver,
self._wait_timeout).until(EC.visibility_of_element_located((By.XPATH, canvas_index_locator)))
14 changes: 6 additions & 8 deletions frontend/tests/lib/Variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def load_from_file(self):
def do_load_file(self, main_page, var_name):
print("...click on 'Load' button on 'Load Variable' pop up")
self.driver.find_element_by_xpath(self._load_button_locator).click()
##time.sleep(4)
main_page.wait_till_file_loaded(var_name)

def close(self):
Expand Down Expand Up @@ -81,7 +80,6 @@ def __init__(self, driver):
super(FileExplorerModal, self).__init__(driver)

def _validate_page(self, driver):
time.sleep(3)
title = driver.find_element_by_xpath(self._file_explorer_title_locator).text.strip()
if "File Explorer" not in title:
raise InvalidPageException("Pop up does not show 'File Explorer'")
Expand All @@ -103,7 +101,7 @@ def __go_to_root_dir(self):
if len(paths_elements) == 0:
print("...at root dir")
at_root_dir = True
time.sleep(3)
time.sleep(self._delay)

def __get_sample_file(self, filename):
# select each path specified in the filename from the scoll list of
Expand All @@ -116,22 +114,22 @@ def __get_sample_file(self, filename):
print("...click on {p}".format(p=p))
path_element = paths_list_element.find_element_by_xpath(path_locator)
path_element.click()
time.sleep(2)
time.sleep(self._delay)

print("...click on 'Select' button in File Explorer pop up")
self.driver.find_element_by_xpath(self._file_explorer_select_locator).click()
time.sleep(5)

# verify that the Load Variable pop up says the selected filename.

# verify that the Load Variable pop up says the selected filename
# in the 'File' input area
file_input_area_locator = "//input[@value='{f}']".format(f=filename)
self.driver.find_element_by_xpath(file_input_area_locator)


def load_a_sample_file(self, filename):
# /Users/muryanto1/work/vcdat/miniconda2/envs/vcdat/share/uvcdat/sample_data/clt.nc
# sys.prefix: /Users/muryanto1/work/vcdat/miniconda2/envs/vcdat
print("xxx in load_a_sample_file: {f}".format(f=filename))
self.__go_to_root_dir()
time.sleep(1)
self.__get_sample_file(filename)


Expand Down

0 comments on commit db75809

Please sign in to comment.