Commit b4f56eee authored by Swergas's avatar Swergas

implement last steps of scenario 2

parent 2a76429a
......@@ -48,8 +48,8 @@ let basic_check_private_key s =
if i < n then
match s.[i] with
| '"' -> middle (i+1)
| _ -> failwith "Must start with a double quote"
else failwith "Too short"
| _ -> failwith "Must start with a double quote (character given was another character)"
else failwith "Must start with a double quote (empty string given)"
and middle i =
if i < n then
match s.[i] with
......
......@@ -1952,7 +1952,9 @@ let election_admin election metadata state get_tokens_decrypt () =
[pcdata "encrypted tally"]
(uuid, ESETally);
pcdata " has been computed. Its hash is ";
b [pcdata hash];
b ~a:[a_id "encrypted_tally_hash"] [
pcdata hash
];
pcdata ".";
];
div [
......
......@@ -551,44 +551,11 @@ pris en compte.
self.some_voters_cast_their_vote(voters_who_will_vote_now_data)
def administrator_does_tallying_of_election(self):
browser = self.browser
# Alice goes to the election page
election_url = self.election_page_url # Could also be obtained with self.voters_data[self.voters_email_addresses[0]]["election_page_url"]
browser.get(election_url)
wait_a_bit()
# She clicks on the "Administer this election" link
administration_link_label = "Administer this election"
administration_link_element = wait_for_an_element_with_partial_link_text_exists(browser, administration_link_label, settings.EXPLICIT_WAIT_TIMEOUT)
administration_link_element.click()
# She logs in as administrator
log_in_as_administrator(browser, from_a_login_page=True)
wait_a_bit()
# She clicks on the "Close election" button
close_election_button_label = "Close election"
close_election_button_css_selector = build_css_selector_to_find_buttons_in_page_content_by_value(close_election_button_label)
close_election_button_element = wait_for_element_exists(browser, close_election_button_css_selector, settings.EXPLICIT_WAIT_TIMEOUT)
close_election_button_element.click()
wait_a_bit()
# She clicks on the "Proceed to vote counting" button
proceed_button_label = "Proceed to vote counting"
proceed_button_css_selector = build_css_selector_to_find_buttons_in_page_content_by_value(proceed_button_label)
proceed_button_element = wait_for_element_exists(browser, proceed_button_css_selector, settings.EXPLICIT_WAIT_TIMEOUT)
proceed_button_element.click()
wait_a_bit()
# FIXME: If no voter has cast their vote, it shows a "Internal Server Error" "Error 500" page
def administrator_verifies_vote_results(self):
"""
Initial browser (required) state: on the vote results page
Final browser state: on the accepted ballots page
She checks consistency of the vote result:
- 1) She checks that the number of accepted ballots is the same as the number of voters who voted
- 2) For each available answer in the question, she checks that the total number of votes in favor of Answer X displayed in result page is the same as the sum of votes for Answer X in all votes of voters who voted that have been randomly generated in advance
......@@ -615,6 +582,8 @@ pris en compte.
Where <...> is a link
"""
browser = self.browser
# - 1) She checks that the number of accepted ballots is the same as the number of voters who voted
main_css_selector = "#main"
......@@ -688,6 +657,46 @@ class BeleniosTestElectionScenario1(BeleniosElectionTestBase):
self.fake_sent_emails_manager.uninstall_fake_sendmail_log_file()
def administrator_does_tallying_of_election(self):
browser = self.browser
# Alice goes to the election page
election_url = self.election_page_url # Could also be obtained with self.voters_data[self.voters_email_addresses[0]]["election_page_url"]
browser.get(election_url)
wait_a_bit()
# She clicks on the "Administer this election" link
administration_link_label = "Administer this election"
administration_link_element = wait_for_an_element_with_partial_link_text_exists(browser, administration_link_label, settings.EXPLICIT_WAIT_TIMEOUT)
administration_link_element.click()
# She logs in as administrator
log_in_as_administrator(browser, from_a_login_page=True)
wait_a_bit()
# She clicks on the "Close election" button
close_election_button_label = "Close election"
close_election_button_css_selector = build_css_selector_to_find_buttons_in_page_content_by_value(close_election_button_label)
close_election_button_element = wait_for_element_exists(browser, close_election_button_css_selector, settings.EXPLICIT_WAIT_TIMEOUT)
close_election_button_element.click()
wait_a_bit()
# She clicks on the "Proceed to vote counting" button
proceed_button_label = "Proceed to vote counting"
proceed_button_css_selector = build_css_selector_to_find_buttons_in_page_content_by_value(proceed_button_label)
proceed_button_element = wait_for_element_exists(browser, proceed_button_css_selector, settings.EXPLICIT_WAIT_TIMEOUT)
proceed_button_element.click()
wait_a_bit()
# FIXME: If no voter has cast their vote, it shows a "Internal Server Error" "Error 500" page
self.administrator_verifies_vote_results()
def test_scenario_1_simple_vote(self):
console_log("### Starting step: administrator_creates_election")
self.administrator_creates_election()
......
This diff is collapsed.
......@@ -10,32 +10,50 @@ from selenium.common.exceptions import StaleElementReferenceException
DEFAULT_WAIT_DURATION = 10 # In seconds
class element_has_non_empty_content(object):
class element_has_non_empty_attribute(object):
"""
An expectation for checking that an element has a non-empty innerText attribute.
An expectation for checking that an element has a non-empty value for given attribute.
This class is meant to be used in combination with Selenium's `WebDriverWait::until()`. For example:
```
custom_wait = WebDriverWait(browser, 10)
smart_ballot_tracker_element = custom_wait.until(element_has_non_empty_content((By.ID, "my_id")))
smart_ballot_tracker_element = custom_wait.until(element_has_non_empty_attribute((By.ID, "my_id"), 'value'))
```
:param locator: Selenium locator used to find the element. For example: `(By.ID, "my_id")`
:param attribute: HTML attribute. For example 'innerText' (see `element_has_non_empty_content()` for this), or 'value'
:return: The WebElement once it has a non-empty innerText attribute
"""
def __init__(self, locator):
def __init__(self, locator, attribute):
self.locator = locator
self.attribute = attribute
def __call__(self, driver):
element = driver.find_element(*self.locator) # Finding the referenced element
if not element:
return False
element_content = element.get_attribute('innerText').strip()
element_content = element.get_attribute(self.attribute).strip()
if len(element_content) > 0:
return element
else:
return False
class element_has_non_empty_content(element_has_non_empty_attribute):
"""
An expectation for checking that an element has a non-empty innerText attribute.
This class is meant to be used in combination with Selenium's `WebDriverWait::until()`. For example:
```
custom_wait = WebDriverWait(browser, 10)
smart_ballot_tracker_element = custom_wait.until(element_has_non_empty_content((By.ID, "my_id")))
```
:param locator: Selenium locator used to find the element. For example: `(By.ID, "my_id")`
:return: The WebElement once it has a non-empty innerText attribute
"""
def __init__(self, locator):
super().__init__(locator, 'innerText')
class an_element_with_partial_link_text_exists(object):
def __init__(self, partial_link_text):
self.partial_link_text = partial_link_text
......@@ -93,14 +111,18 @@ def wait_for_element_exists_and_contains_expected_text(browser, css_selector, ex
raise Exception("Could not find expected DOM element '" + css_selector + "' with text content '" + expected_text + "' until timeout of " + str(wait_duration) + " seconds. Page source was: " + str(browser.page_source.encode("utf-8"))) from e
def wait_for_element_exists_and_has_non_empty_content(browser, css_selector, wait_duration=DEFAULT_WAIT_DURATION):
def wait_for_element_exists_and_has_non_empty_attribute(browser, css_selector, attribute, wait_duration=DEFAULT_WAIT_DURATION):
try:
ignored_exceptions = (NoSuchElementException, StaleElementReferenceException,)
custom_wait = WebDriverWait(browser, wait_duration, ignored_exceptions=ignored_exceptions)
element = custom_wait.until(element_has_non_empty_content((By.CSS_SELECTOR, css_selector)))
element = custom_wait.until(element_has_non_empty_attribute((By.CSS_SELECTOR, css_selector), attribute))
return element
except Exception as e:
raise Exception("Could not find expected DOM element '" + css_selector + "' with non-empty content until timeout of " + str(wait_duration) + " seconds") from e
raise Exception("Could not find expected DOM element '" + css_selector + "' with non-empty attribute '" + attribute + "' until timeout of " + str(wait_duration) + " seconds") from e
def wait_for_element_exists_and_has_non_empty_content(browser, css_selector, wait_duration=DEFAULT_WAIT_DURATION):
return wait_for_element_exists_and_has_non_empty_attribute(browser, css_selector, 'innerText', wait_duration)
def wait_for_an_element_with_partial_link_text_exists(browser, partial_link_text, wait_duration=DEFAULT_WAIT_DURATION):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment