Skip to content

Commit

Permalink
starting to update selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwohl committed Jun 9, 2015
1 parent 50b4047 commit e6f22fd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dokomoforms/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3 data-ignore="push" class="welcome_title"> Welcome to Dokomoforms</h3>
</script>

<script type="text/template" id="manage-btn-tpl">
<a class="btn btn-secondary btn-xs" href="/view/<%= survey_id %>" data-id="<%= survey_id %>">Manage Survey</a>
<a class="btn btn-secondary btn-xs btn-manage" href="/view/<%= survey_id %>" data-id="<%= survey_id %>">Manage Survey</a>
</script>


Expand Down
13 changes: 8 additions & 5 deletions dokomoforms/templates/view-survey-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h3>Survey Data</h3>
{% for stats in question_stats['result'] %}
<li>

<div class="question-title-bar {% if stats['question'].type_constraint_name == "location" %} question-location {% end %}"
<div class="question-title-bar question-type-{{ stats['question'].type_constraint_name }} {% if stats['question'].type_constraint_name == "location" %} question-location {% end %}"
{% if stats['question'].type_constraint_name == "location" %} rel="location-map-{{ stats['question'].question_id }}" {% end %}>

{{ stats['question'].sequence_number }}. {{ stats['question'].question_title }}
Expand Down Expand Up @@ -135,6 +135,7 @@ <h3>Survey Data</h3>

<script type="text/javascript">
$(function() {
var map;

$(document).on('click', '.question-title-bar', function(e) {
$el = $(this);
Expand All @@ -145,9 +146,11 @@ <h3>Survey Data</h3>
}
$el.siblings('.question-stats').slideToggle();
if ($el.hasClass('question-location')) {
var id = $el.attr('rel');
console.log(id);
drawMap(id, map_data[id]);
if (!map) {
var id = $el.attr('rel');
console.log(id);
drawMap(id, map_data[id]);
}
}
});

Expand Down Expand Up @@ -198,7 +201,7 @@ <h3>Survey Data</h3>

function drawMap(element_id, map_data) {

var map = L.map(element_id, {
map = L.map(element_id, {
dragging: true,
zoom: 14,
// zoomControl: false,
Expand Down
2 changes: 1 addition & 1 deletion dokomoforms/templates/view-survey.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ <h4>Submissions</h4>

<!-- Templates -->
<script type="text/template" id="view-submission-btn-tpl">
<a class="btn btn-default btn-xs" href="/view/submission/<%= submission_id %>"><span class="glyphicon glyphicon-list-alt"></span> View Submission Details</a>
<a class="btn btn-default btn-xs btn-view-submission" href="/view/submission/<%= submission_id %>"><span class="glyphicon glyphicon-list-alt"></span> View Submission Details</a>
</script>

<script type="text/javascript">
Expand Down
101 changes: 52 additions & 49 deletions tests/selenium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def set_passed(self, *args, **kwargs):


class DriverTest(unittest.TestCase):

def setUp(self):
self.passed = False

Expand Down Expand Up @@ -141,25 +142,26 @@ def tearDown(self):


class SubmissionTest(DriverTest):

@report_success_status
def testSubmitSuccessfully(self): # flake8: noqa
# Log in
self.drv.get(base + '/debug/login/test_email')
self.drv.get(base + '/view')
self.drv.get(base + '/')

# Click on the survey
WebDriverWait(self.drv, 5).until(EC.presence_of_element_located(
(By.XPATH,
'/html/body/div[2]/div/div[2]/div/table/tbody/tr/td[1]/a[1]'))
(By.CLASS_NAME,
'btn-manage'))
)
self.drv.find_element_by_xpath(
'/html/body/div[2]/div/div[2]/div/table/tbody/tr/td[1]/a[1]'
self.drv.find_element_by_class_name(
'btn-manage'
).click()

# Click on the shareable link
# WebDriverWait(self.drv, 4).until(EC.presence_of_element_located(
# (By.XPATH, '/html/body/div[2]/div/a')))
# self.drv.find_element_by_xpath('/html/body/div[2]/div/a').click()
# (By.XPATH, '/html/body/div[3]/div/a')))
# self.drv.find_element_by_xpath('/html/body/div[3]/div/a').click()

# Look into where the link is later...
survey_id = self.drv.current_url.split('/')[-1]
Expand All @@ -168,10 +170,10 @@ def testSubmitSuccessfully(self): # flake8: noqa
# Fill out the survey
self.drv.find_element_by_class_name('start_btn').click()
WebDriverWait(self.drv, 4).until(EC.presence_of_element_located(
(By.XPATH, '/html/body/div[2]/div[2]/input')))
(By.XPATH, '/html/body/div[3]/div[2]/input')))
next_class = 'page_nav__next'
next_button = lambda: self.drv.find_element_by_class_name(next_class)
in_xpath = '/html/body/div[2]/div[2]/'
in_xpath = '/html/body/div[3]/div[2]/'

self.drv.find_elements_by_tag_name('input')[0].send_keys('1')
if self.browser_name == 'safari':
Expand Down Expand Up @@ -239,17 +241,17 @@ def testSubmitSuccessfully(self): # flake8: noqa
else:
self.drv.find_elements_by_tag_name('option')[-1].click()
self.drv.find_element_by_xpath(
'/html/body/div[2]/input').send_keys('other 8')
'/html/body/div[3]/input').send_keys('other 8')
if self.browser_name == 'safari':
self.drv.execute_script("$('input').change()")
next_button().click()
next_button().click() # note question

WebDriverWait(self.drv, 3).until(EC.presence_of_element_located(
(By.CLASS_NAME, 'question__radio__span__btn')))
self.drv.find_element_by_class_name('facility__btn').click()
self.drv.find_element_by_xpath(
'/html/body/div[2]/div[2]/input[2]'
).send_keys('new_test_facility')
self.drv.find_element_by_class_name(
'facility_name_input').send_keys('new_test_facility')
if self.browser_name == 'android':
self.drv.find_element_by_tag_name('select').click()
self.drv.switch_to.window('NATIVE_APP')
Expand All @@ -265,28 +267,18 @@ def testSubmitSuccessfully(self): # flake8: noqa
self.drv.find_element_by_class_name('sync_btn').click()

# Check the submissions
self.drv.get(base + '/view')
WebDriverWait(self.drv, 5).until(EC.presence_of_element_located(
(By.XPATH,
'/html/body/div[2]/div/div[2]/div/table/tbody/tr/td[1]/a[1]'))
)
self.drv.find_element_by_xpath(
'/html/body/div[2]/div/div[2]/div/table/tbody/tr/td[1]/a[1]'
).click()
self.drv.get(base + '/view/'+survey_id)
WebDriverWait(self.drv, 5).until(EC.presence_of_element_located(
(By.XPATH,
'/html/body/div[2]/div/div[3]/div/div/div['
'2]/div/table/tbody/tr/td[4]/a')
(By.CLASS_NAME, 'btn-view-submission')
))
submission_link = self.drv.find_element_by_xpath(
'/html/body/div[2]/div/div[3]/div/div/div['
'2]/div/table/tbody/tr/td[4]/a')
submission_link = self.drv.find_element_by_class_name(
'btn-view-submission')
self.drv.execute_script(
'window.scrollTo(0, {});'.format(submission_link.location['y']))
submission_link.click()

# Check the submission
self.assertIn('data">\n\n1', self.drv.page_source)
self.assertIn('Submission Detail', self.drv.page_source)
self.assertIn('1. choice 1', self.drv.page_source)
self.assertIn('3.3', self.drv.page_source)
self.assertIn('4. date question',
Expand All @@ -301,6 +293,7 @@ def testSubmitSuccessfully(self): # flake8: noqa


class TypeTest(DriverTest):

def tearDown(self):
super().tearDown()
connection.execute(survey_table.delete().where(
Expand Down Expand Up @@ -333,8 +326,9 @@ def _create_survey(self, type_constraint_name,


class IntegerTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('integer')

Expand All @@ -353,22 +347,25 @@ def testVisualization(self):
# Log in
self.drv.get(base + '/debug/login/test_email')

# Get the visualization page
self.drv.get(base + '/visualize/' + question_id)
# Go to the survey data page
self.drv.get(base + '/view/data/' + survey_id)

# Test it
line_graph = self.drv.find_element_by_id('line_graph')
self.assertTrue(line_graph.is_displayed())
self.drv.find_element_by_css_selector('.question-type-integer').click()
stats = self.drv.find_element_by_css_selector(
'.question-type-integer + .question-stats')
self.assertTrue(stats.is_displayed())

WebDriverWait(self.drv, 5).until(
EC.presence_of_element_located((By.ID, 'bar_graph')))
bar_graph = self.drv.find_element_by_id('bar_graph')
self.assertTrue(bar_graph.is_displayed())
# WebDriverWait(self.drv, 5).until(
# EC.presence_of_element_located((By.ID, 'bar_graph')))
# bar_graph = self.drv.find_element_by_id('bar_graph')
# self.assertTrue(bar_graph.is_displayed())


class DecimalTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('decimal')

Expand Down Expand Up @@ -401,8 +398,9 @@ def testVisualization(self):


class TextTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('text')

Expand Down Expand Up @@ -435,8 +433,9 @@ def testVisualization(self):


class DateTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('date')

Expand Down Expand Up @@ -477,8 +476,9 @@ def testVisualization(self):


class TimeTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('time')

Expand Down Expand Up @@ -519,8 +519,9 @@ def testVisualization(self):


class MultipleChoiceTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('multiple_choice',
choices=['only choice'])
Expand Down Expand Up @@ -559,8 +560,9 @@ def testVisualization(self):


class MultiSelectTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey(
'multiple_choice',
Expand Down Expand Up @@ -621,12 +623,11 @@ def testVisualization(self):

# Get the submission page
self.drv.get(base + '/view/' + survey_id)
link_xpath = '/html/body/div[2]/div/div[3]/div/div/div[' \
'2]/div/table/tbody/tr/td[4]/a'
WebDriverWait(self.drv, 5).until(EC.presence_of_element_located(
(By.XPATH, link_xpath))
)
submission_link = self.drv.find_element_by_xpath(link_xpath)
(By.CLASS_NAME, 'btn-view-submission')
))
submission_link = self.drv.find_element_by_class_name(
'btn-view-submission')
self.drv.execute_script(
'window.scrollTo(0, {});'.format(submission_link.location['y']))
submission_link.click()
Expand Down Expand Up @@ -654,8 +655,9 @@ def testVisualization(self):


class LocationTest(TypeTest):

@report_success_status
def testVisualization(self):
def testDetailDisplay(self):
# Create the survey
survey_id, question_id = self._create_survey('location')

Expand Down Expand Up @@ -704,3 +706,4 @@ def testVisualization(self):

if __name__ == '__main__':
unittest.main()

0 comments on commit e6f22fd

Please sign in to comment.