Files
PyRIGS/RIGS/tests/pages.py
Arona Jones 2bf0175786 Toolchain/Dependency Upgrade (#418)
* Upgrade to heroku-20 stack

* Move some gulp deps to dev rather than prod

* npm upgrade

* Fix audit time check in asset audit test

* Attempt at parallelising tests where possible

* Add basic calendar button test

Mainly to pickup on FullCalendar loading errors

* Upgrade python deps

* Tends to help if I push valid yaml

* You valid now?

* Fix whoops in requirements.txt

* Change python ver

* Define service in coveralls task

* Run parallelised RIGS tests as one matrix job

* Update python version in tests

* Cache python dependencies

Should majorly speedup parallelillelelised testing

* Purge old vagrant config

* No Ruby compass bodge, no need for rubocop!

* Purge old .idea config

* Switch to gh-a artifact uploading instead of imgur 'hack'

For test failure screenshots. Happy now @mattysmith22? ;p

* Oops, remove unused import

* Exclude tests from the coverage stats

Seems to be artifically deflating our stats

* Refactor asset audit tests with better selectors

Also fixed a silly title error with the modal

* Add title checking to the slightly insane assets test

* Fix unauth test to not just immediately pass out

* Upload failure screenshots as individual artifacts not a zip

Turns out I can't unzip things from my phone, which is a pain

* Should fix asset test on CI

* What about this?

* What about this?

Swear I spend my life jiggerypokerying the damn test suite...

* Does this help the coverage be less weird?

* Revert "Does this help the coverage be less weird?"

This reverts commit 39ab9df836.

* Use pytest as our test runner for better parallelism

Also rewrote some asset tests to be in the pytest style. May do some more. Some warnings cleaned up in the process.

* Bah, codestyle

* Oops, remove obsolete if check

* Fix screenshot uploading on CI (again)

* Try this way of parallel coverage

* Add codeclimate maintainability badge

* Remove some unused gulp dependencies

* Run asset building serverside

* Still helps if I commit valid YAML

* See below

* Different approach to CI dependencies

* Exclude node_modules from codestyle

* Does this work?

* Parallel parallel builds were giving me a headache, try this

* Update codeclimate settings, purge some config files

* Well the YAML was *syntactically* valid....

* Switch back to old coveralls method

* Fix codeclimate config, mark 2

* Attempt to bodge asset test

* Oops, again

Probably bedtime..

* Might fix heroku building

* Attempt #2 at fixing heroku

* Belt and braces approach to coverage

* Github, you need a Actions YAML validator!

* Might fix actions?

* Try ignoring some third party deprecation warnings

* Another go at making coverage show up

* Some template cleanup

* Minor python cleanup

* Import optimisation

* Revert "Minor python cleanup"

This reverts commit 6a4620a2e5.

* Add format arg to coverage command

* Ignore test directories from Heroku slug

* Maybe this works to purge deps postbuild

* Bunch of test refactoring

* Restore signals import, screw you import optimisation

* Further template refactoring

* Add support for running tests with geckodriver, do this on CI

* Screw you codestyle

* Disable firefox tests for now

That was way more errors than I expected

* Run cleanup script from the right location

* Plausibly fix tests

* Helps if I don't delete the pipeline folder prior to collectstatic

* Enable whitenoise

* Can I delete pipeline here?

* Allow seconds difference in assert_times_equal

* Disable codeclimate

* Remove not working rm command

* Maybe this fixes coverage?

* Try different coverage reporter

* Fix search_help to need login

* Made versioning magic a bit less expansive

We have more apps than I thought...

* Fix IDI0T error in Assets URLS

* Refactor 'no access to unauthed' test to cover all of PyRIGS

* Add RAs/Checklists to sample data generator

* Fix some HTML errors in templates

Which apparently only Django's HTML parser cares about, browsers DGAF...

* Port title test to project level

* Fix more HTML

* Fix cable type detail
2021-01-31 04:05:33 +00:00

345 lines
13 KiB
Python

from django.urls import reverse
from pypom import Region
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from PyRIGS.tests import regions
from PyRIGS.tests.pages import BasePage, FormPage
from RIGS.tests import regions as rigs_regions
class Index(BasePage):
URL_TEMPLATE = reverse('index')
class Rigboard(BasePage):
URL_TEMPLATE = reverse('rigboard')
_add_item_selector = (By.XPATH, "//a[contains(@class,'btn-primary') and contains(., 'New')]")
_event_row_locator = (By.ID, 'event_row')
def add(self):
self.find_element(*self._add_item_selector).click()
class EventListRow(Region):
_event_number_locator = (By.ID, "event_number")
_event_dates_locator = (By.ID, "event_dates")
_event_details_locator = (By.ID, "event_details")
_event_mic_locator = (By.ID, "event_mic")
@property
def id(self):
return self.find_element(*self._event_number_locator).text
@property
def dates(self):
return self.find_element(*self._event_dates_locator).text
@property
def details(self):
return self.find_element(*self._event_details_locator).text
@property
def mic(self):
return self.find_element(*self._event_mic_locator).text
@property
def events(self):
return [self.EventListRow(self, i) for i in self.find_elements(*self._event_row_locator)]
class EventDetail(BasePage):
URL_TEMPLATE = 'event/{event_id}'
# TODO Refactor into regions to match template fragmentation
_event_name_selector = (By.XPATH, '//h1')
_person_panel_selector = (By.XPATH, '//div[contains(text(), "Contact Details")]/..')
_name_selector = (By.XPATH, '//dt[text()="Person"]/following-sibling::dd[1]')
_email_selector = (By.XPATH, '//dt[text()="Email"]/following-sibling::dd[1]')
_phone_selector = (By.XPATH, '//dt[text()="Phone Number"]/following-sibling::dd[1]')
_event_table_selector = (By.ID, 'item-table')
@property
def event_name(self):
return self.find_element(*self._event_name_selector).text
@property
def name(self):
return self.find_element(*self._person_panel_selector).find_element(*self._name_selector).text
@property
def email(self):
return self.find_element(*self._person_panel_selector).find_element(*self._email_selector).text
@property
def phone(self):
return self.find_element(*self._person_panel_selector).find_element(*self._phone_selector).text
@property
def item_table(self):
return self.find_element(*self._event_table_selector)
class CreateEvent(FormPage):
URL_TEMPLATE = reverse('event_create')
_is_rig_selector = (By.ID, 'is_rig-selector')
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
_person_selector_selector = (By.XPATH, '//*[@id="id_person"]/..')
_venue_selector_selector = (By.XPATH, '//*[@id="id_venue"]/..')
_mic_selector_selector = (By.XPATH, '//*[@id="form-hws"]/div[7]/div[1]/div/div')
_add_person_selector = (By.XPATH, '//a[@data-target="#id_person" and contains(@href, "add")]')
_add_item_selector = (By.XPATH, '//button[contains(@class, "item-add")]')
_event_table_selector = (By.ID, 'item-table')
_warning_selector = (By.XPATH, '/html/body/div[1]/div[1]')
form_items = {
'description': (regions.TextBox, (By.ID, 'id_description')),
'name': (regions.TextBox, (By.ID, 'id_name')),
'start_date': (regions.DatePicker, (By.ID, 'id_start_date')),
'start_time': (regions.TimePicker, (By.ID, 'id_start_time')),
'end_date': (regions.DatePicker, (By.ID, 'id_end_date')),
'end_time': (regions.TimePicker, (By.ID, 'id_end_time')),
'access_at': (regions.DateTimePicker, (By.ID, 'id_access_at')),
'meet_at': (regions.DateTimePicker, (By.ID, 'id_meet_at')),
'dry_hire': (regions.CheckBox, (By.ID, 'id_dry_hire')),
'status': (regions.SingleSelectPicker, (By.ID, 'id_status')),
'collected_by': (regions.TextBox, (By.ID, 'id_collector')),
'po': (regions.TextBox, (By.ID, 'id_purchase_order')),
'notes': (regions.TextBox, (By.ID, 'id_notes'))
}
def select_event_type(self, type_name):
self.find_element(By.XPATH, '//button[.="{}"]'.format(type_name)).click()
def item_row(self, ID):
return rigs_regions.ItemRow(self, self.find_element(By.ID, "item-" + ID))
@property
def item_table(self):
return self.find_element(*self._event_table_selector)
@property
def warning(self):
return self.find_element(*self._warning_selector).text
@property
def is_expanded(self):
return self.find_element(*self._submit_locator).is_displayed()
@property
def person_selector(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._person_selector_selector))
@property
def venue_selector(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._venue_selector_selector))
@property
def mic_selector(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._mic_selector_selector))
def add_person(self):
self.find_element(*self._add_person_selector).click()
return regions.Modal(self, self.driver.find_element_by_id('modal'))
def add_event_item(self):
self.find_element(*self._add_item_selector).click()
element = self.driver.find_element_by_id('itemModal')
self.wait.until(EC.visibility_of(element))
return rigs_regions.ItemModal(self, element)
@property
def success(self):
return '/create' not in self.driver.current_url
class DuplicateEvent(CreateEvent):
URL_TEMPLATE = 'event/{event_id}/duplicate'
@property
def success(self):
return '/duplicate' not in self.driver.current_url
class EditEvent(CreateEvent):
URL_TEMPLATE = 'event/{event_id}/edit'
@property
def success(self):
return '/edit' not in self.driver.current_url
class CreateRiskAssessment(FormPage):
URL_TEMPLATE = 'event/{event_id}/ra/'
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
_power_mic_selector = (By.CSS_SELECTOR, ".bootstrap-select")
form_items = {
'nonstandard_equipment': (regions.RadioSelect, (By.ID, 'id_nonstandard_equipment')),
'nonstandard_use': (regions.RadioSelect, (By.ID, 'id_nonstandard_use')),
'contractors': (regions.RadioSelect, (By.ID, 'id_contractors')),
'other_companies': (regions.RadioSelect, (By.ID, 'id_other_companies')),
'crew_fatigue': (regions.RadioSelect, (By.ID, 'id_crew_fatigue')),
'general_notes': (regions.TextBox, (By.ID, 'id_general_notes')),
'big_power': (regions.RadioSelect, (By.ID, 'id_big_power')),
'outside': (regions.RadioSelect, (By.ID, 'id_outside')),
'generators': (regions.RadioSelect, (By.ID, 'id_generators')),
'other_companies_power': (regions.RadioSelect, (By.ID, 'id_other_companies_power')),
'nonstandard_equipment_power': (regions.RadioSelect, (By.ID, 'id_nonstandard_equipment_power')),
'multiple_electrical_environments': (regions.RadioSelect, (By.ID, 'id_multiple_electrical_environments')),
'power_notes': (regions.TextBox, (By.ID, 'id_power_notes')),
'noise_monitoring': (regions.RadioSelect, (By.ID, 'id_noise_monitoring')),
'sound_notes': (regions.TextBox, (By.ID, 'id_sound_notes')),
'known_venue': (regions.RadioSelect, (By.ID, 'id_known_venue')),
'safe_loading': (regions.RadioSelect, (By.ID, 'id_safe_loading')),
'safe_storage': (regions.RadioSelect, (By.ID, 'id_safe_storage')),
'area_outside_of_control': (regions.RadioSelect, (By.ID, 'id_area_outside_of_control')),
'barrier_required': (regions.RadioSelect, (By.ID, 'id_barrier_required')),
'nonstandard_emergency_procedure': (regions.RadioSelect, (By.ID, 'id_nonstandard_emergency_procedure')),
'special_structures': (regions.RadioSelect, (By.ID, 'id_special_structures')),
'persons_responsible_structures': (regions.TextBox, (By.ID, 'id_persons_responsible_structures')),
'suspended_structures': (regions.RadioSelect, (By.ID, 'id_suspended_structures')),
'supervisor_consulted': (regions.CheckBox, (By.ID, 'id_supervisor_consulted')),
'rigging_plan': (regions.TextBox, (By.ID, 'id_rigging_plan')),
}
@property
def power_mic(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._power_mic_selector))
@property
def success(self):
return '/event/ra' in self.driver.current_url
class EditRiskAssessment(CreateRiskAssessment):
URL_TEMPLATE = 'event/ra/{pk}/edit'
@property
def success(self):
return '/edit' not in self.driver.current_url
class CreateEventChecklist(FormPage):
URL_TEMPLATE = 'event/{event_id}/checklist'
_submit_locator = (By.XPATH, "//button[@type='submit' and contains(., 'Save')]")
_power_mic_selector = (By.XPATH, "//div[@id='id_power_mic-group']//div[contains(@class, 'bootstrap-select')]")
_add_vehicle_locator = (By.XPATH, "//button[contains(., 'Vehicle')]")
_add_crew_locator = (By.XPATH, "//button[contains(., 'Crew')]")
form_items = {
'safe_parking': (regions.CheckBox, (By.ID, 'id_safe_parking')),
'safe_packing': (regions.CheckBox, (By.ID, 'id_safe_packing')),
'exits': (regions.CheckBox, (By.ID, 'id_exits')),
'trip_hazard': (regions.CheckBox, (By.ID, 'id_trip_hazard')),
'warning_signs': (regions.CheckBox, (By.ID, 'id_warning_signs')),
'ear_plugs': (regions.CheckBox, (By.ID, 'id_ear_plugs')),
'hs_location': (regions.TextBox, (By.ID, 'id_hs_location')),
'extinguishers_location': (regions.TextBox, (By.ID, 'id_extinguishers_location')),
'rcds': (regions.CheckBox, (By.ID, 'id_rcds')),
'supply_test': (regions.CheckBox, (By.ID, 'id_supply_test')),
'earthing': (regions.CheckBox, (By.ID, 'id_earthing')),
'pat': (regions.CheckBox, (By.ID, 'id_pat')),
'source_rcd': (regions.CheckBox, (By.ID, 'id_source_rcd')),
'labelling': (regions.CheckBox, (By.ID, 'id_labelling')),
'fd_voltage_l1': (regions.TextBox, (By.ID, 'id_fd_voltage_l1')),
'fd_voltage_l2': (regions.TextBox, (By.ID, 'id_fd_voltage_l2')),
'fd_voltage_l3': (regions.TextBox, (By.ID, 'id_fd_voltage_l3')),
'fd_phase_rotation': (regions.CheckBox, (By.ID, 'id_fd_phase_rotation')),
'fd_earth_fault': (regions.TextBox, (By.ID, 'id_fd_earth_fault')),
'fd_pssc': (regions.TextBox, (By.ID, 'id_fd_pssc')),
'w1_description': (regions.TextBox, (By.ID, 'id_w1_description')),
'w1_polarity': (regions.CheckBox, (By.ID, 'id_w1_polarity')),
'w1_voltage': (regions.TextBox, (By.ID, 'id_w1_voltage')),
'w1_earth_fault': (regions.TextBox, (By.ID, 'id_w1_earth_fault')),
}
def add_vehicle(self):
self.find_element(*self._add_vehicle_locator).click()
def add_crew(self):
self.find_element(*self._add_crew_locator).click()
@property
def power_mic(self):
return regions.BootstrapSelectElement(self, self.find_element(*self._power_mic_selector))
@property
def success(self):
return '{event_id}' not in self.driver.current_url
class GenericList(BasePage):
_search_selector = (By.CSS_SELECTOR, 'div.input-group:nth-child(2) > input:nth-child(1)')
_search_go_selector = (By.ID, 'id_search')
_add_item_selector = (By.CSS_SELECTOR, '.btn-success')
class UserPage(BasePage):
URL_TEMPLATE = 'user/'
_api_key_selector = (By.ID, 'api-key')
_cal_url_selector = (By.ID, 'cal-url')
_generation_button_selector = (By.LINK_TEXT, 'Generate API Key')
@property
def api_key(self):
return self.find_element(*self._api_key_selector).text
@property
def cal_url(self):
return self.find_element(*self._cal_url_selector).text
def toggle_filter(self, type_name):
self.find_element(By.XPATH, "//input[@value='" + type_name + "']").click()
def generate_key(self):
self.find_element(*self._generation_button_selector).click()
class CalendarPage(BasePage):
URL_TEMPLATE = 'rigboard/calendar'
_go_locator = (By.ID, 'go-to-date-button')
_today_selector = (By.ID, 'today-button')
_prev_selector = (By.ID, 'prev-button')
_next_selector = (By.ID, 'next-button')
_month_selector = (By.ID, 'month-button')
_week_selector = (By.ID, 'week-button')
_day_selector = (By.ID, 'day-button')
def go(self):
return self.find_element(*self._go_locator).click()
@property
def target_date(self):
return regions.DatePicker(self, self.find_element(By.ID, 'go-to-date-input'))
def today(self):
return self.find_element(*self._today_selector).click()
def prev(self):
return self.find_element(*self._prev_selector).click()
def next(self):
return self.find_element(*self._next_selector).click()
def month(self):
return self.find_element(*self._month_selector).click()
def week(self):
return self.find_element(*self._week_selector).click()
def day(self):
return self.find_element(*self._day_selector).click()