Skip to content

Commit

Permalink
adding selenium testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Muryanto authored and Muryanto committed Aug 16, 2018
1 parent 459b3b3 commit 63696a4
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 17 deletions.
76 changes: 76 additions & 0 deletions frontend/tests/lib/AddVariable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import time

from BasePage import BasePage
from BasePage import InvalidPageException

class AddVariableModal(BasePage):

# _file_explorer_locator = "btn-primary"
_load_from_locator = "load-from"

def __init__(self, driver):
super(AddVariableModal, self).__init__(driver)

def _validate_page(self, driver):
title = driver.find_element_by_class_name("modal-title").text.strip()
if "Load Variable" not in title:
raise InvalidPageException("Pop up does not show 'Load Variable'")

@property
def load_from_file(self):
print("xxx load_from_file xxx")

load_from = self.driver.find_element_by_class_name(self._load_from_locator)
load_button = load_from.find_element_by_xpath('.//span[@class="input-group-btn"]//button[@class="btn btn-primary"]')
return load_button.click()



class FileExplorerModal(BasePage):

_dialogs_locator = '//div[@role="dialogs"]'

_left_arrow_locator = '//div[@role="dialog"]//button[@class="path-back-button"]'
_curr_path_locator = '//div[@role="dialog"]//div[@class="breadcrumbs"]'
_list_of_paths_locator = './/a[@class="path-segment"]'
def __init__(self, driver):
super(FileExplorerModal, self).__init__(driver)

def _validate_page(self, driver):
time.sleep(3)
#title = driver.find_element_by_class_name("modal-title").text.strip()
#title = driver.find_element_by_xpath(self._pop_up_title_locator).text.strip()

print("xxx FileExplorerModal._validate_page() xxx")
all_dialogs = driver.find_elements_by_xpath(self._dialogs_locator)
for dialog in all_dialogs:
dialog_attr = dialog.get_attribute("aria-hidden")
if dialog_attr and dialog_attr == 'true':
continue
title = dialog.find_element_by_class_name("modal-title").text.strip()
print("xxx xxx xxx title: {t}".format(t=title))
if "File Explorer" not in title:
raise InvalidPageException("Pop up does not show 'File Explorer'")
else:
print("Found File Explorer title")
return

def __go_to_root_dir(self):
at_root_dir = False
left_arrow_element = self.driver.find_element_by_xpath(self._left_arrow_locator)
print("xxx xxx __go_to_root_dir xxx")
while at_root_dir == False:
print("xxx xxx ...__go_to_root_dir() xxx")
left_arrow_element.click()
curr_path_element = self.driver.find_element_by_xpath(self._curr_path_locator)
paths_elements = curr_path_element.find_elements_by_xpath(self._list_of_paths_locator)
if len(paths_elements) == 0:
print("xxx no more elements xxx")

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(3)
return 0
16 changes: 16 additions & 0 deletions frontend/tests/lib/BasePage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from abc import abstractmethod

class BasePage(object):
""" All page objects inherit from this """
def __init__(self, driver):
self._validate_page(driver)
self.driver = driver

@abstractmethod
def _validate_page(self, driver):
return

class InvalidPageException(Exception):
""" Throw this exception when we do not find the correct page """
pass

17 changes: 12 additions & 5 deletions frontend/tests/lib/BaseTestCase.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@

import os
import time
import unittest
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

class BaseTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.maximize_window()

self.driver.get("http://localhost:5000")
options = Options()
options.add_argument("--headless")
self.driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver")
#self.driver = webdriver.Firefox(firefox_options=options, executable_path="/usr/local/bin/geckodriver")
self.driver.implicitly_wait(5)
#self.driver.maximize_window()
self.driver.get("localhost:5000")
time.sleep(3)

def tearDown(self):
self.driver.quit()
Expand Down
21 changes: 11 additions & 10 deletions frontend/tests/lib/BaseTestCase.py~
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@

import os
import time
import unittest
from selenium import webdriver

this_dir = os.path.abspath(os.path.dirname(__file__))
libs_dir = os.path.join(this_dir, '..', 'libs')
sys.path.append(libs_dir)


from selenium.webdriver.firefox.options import Options

class BaseTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
options = Options()
options.add_argument("--headless")
self.driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver")
#self.driver = webdriver.Firefox(firefox_options=options, executable_path="/usr/local/bin/geckodriver")
self.driver.implicitly_wait(5)
self.driver.maximize_window()

self.driver.get("http://localhost:5000")
self.driver.get("localhost:5000")
time.sleep(3)

def tearDown(self):
self.driver.quit()
Expand Down
15 changes: 15 additions & 0 deletions frontend/tests/lib/MainPage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import time

from BasePage import BasePage
from BasePage import InvalidPageException

class MainPage(BasePage):

def __init__(self, driver):
super(MainPage, self).__init__(driver)

@property
def add_variable(self):
variables = self.driver.find_element_by_class_name("var-list-container")
return variables.find_element_by_class_name("action-add-button").click()

18 changes: 16 additions & 2 deletions frontend/tests/testcases/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import unittest
import os
import sys
import time

this_dir = os.path.abspath(os.path.dirname(__file__))
lib_dir = os.path.join(this_dir, '..', 'lib')
sys.path.append(lib_dir)

# from BaseTestCase import BaseTestCase
from BaseTestCase import BaseTestCase

from MainPage import MainPage
from AddVariable import AddVariableModal
from AddVariable import FileExplorerModal

class AddVariableTest(BaseTestCase):
def testAddVariable(self):
print("xxx testAddVariable xxx")

main_page = MainPage(self.driver)
add_variable_pop_up = main_page.add_variable
time.sleep(3)

add_variable = AddVariableModal(self.driver)
load_file_pop_up = add_variable.load_from_file
time.sleep(3)

file_explorer_pop_up = FileExplorerModal(self.driver)
data_file = "/Users/muryanto1/work/vcdat/miniconda2/envs/vcdat/share/uvcdat/sample_data/clt.nc"
tmp_ret_val = file_explorer_pop_up.load_a_sample_file(data_file)

if __name__ == '__main__':
unittest.main(verbosity=2)
Expand Down

0 comments on commit 63696a4

Please sign in to comment.