def test_pause_at_update(self, bp: BasePage, pp: PopulationPage): """ Tests that 'Pause at Update' setting will allow user to automatically pause the experiment at the given update. :return: None. """ # Setup pause settings. pp.enable_pause_at_update() pp.edit_pause_update(9) # Set up the rest of the experiment. bp.add_ancestor_to_dish() # Run the experiment. bp.run_from_menu() # Wait long enough for experiment to have reached update 9. bp.util.sleep(10, "Waiting for experiment to pause automatically.") # Check that pause worked properly. assert pp.get_pop_current_update() == 9 # Wait to make sure it is paused. bp.util.sleep(1, "Ensuring that experiment is paused.") assert pp.get_pop_current_update() == 9
def __init__(self, menus): BasePage.__init__(self) self.menus = menus self.menu_level_1 = (By.XPATH, f"/html/body/aside/span/nav/ul/li[@title='{menus[0]}']") self.menu_level_2 = ( By.XPATH, f"/html/body/aside/span/nav/ul/li[@title='{menus[0]}']/ul/li[@title='{menus[1]}']/a") if (len(self.menus) > 2): self.menu_level_3 = (By.XPATH, f"/html/body/aside/span/nav/ul/li[@title='{menus[0]}']/ul/li[@title='{menus[1]}']/ul/li[@title='{menus[2]}']")
def test_go_to_analysis(self, bp: BasePage): """ Tests navigating to the Analysis page. :return: None. """ bp.go_to_analysis() assert bp.analysis_displayed() bp.util.sleep(3)
def test_go_to_organism(self, bp: BasePage): """ Tests navigating to the Organism page. :return: None. """ bp.go_to_organism() assert bp.organism_displayed() bp.util.sleep(3)
def hard_reset(self, closing_assertions, bp: BasePage): """ Performs a 'hard reset' at the beginning of an experiment by refreshing the Avida-ED webpage and waits for it to load completely. Used by default, since tests no longer run in specific orders. :return: None. """ yield bp.refresh_avida_ed()
def test_freezer_menu_launch(self, bp: BasePage): """ Tests that the correct menu options in the Freezer tab are usable on startup. :return: None. """ assert not bp.can_save_current_pop() assert not bp.can_save_selected_org() assert not bp.can_save_offspring_org()
def __init__(self): BasePage.__init__(self) self.query_btn = (By.CSS_SELECTOR, '.btn-search') self.name = (By.CSS_SELECTOR, '#ACCNAME') self.retult_head = ( By.CSS_SELECTOR, '.dataTables_scrollHeadInner > table:nth-child(1) > thead:nth-child(1) > tr:nth-child(1)' ) self.result = (By.CSS_SELECTOR, '#datatable_col_reorder > tbody:nth-child(2)')
def test_control_menu_launch(self, bp: BasePage): """ Tests that the correct menu options in the Control tab are usable on startup. :return: None. """ assert bp.can_run_from_menu() assert not bp.can_pause_from_menu() assert not bp.can_bring_to_org_window() assert not bp.can_bring_child_to_org_window()
def test_go_to_population(self, bp: BasePage): """ Tests navigating to the Population page. Should not be run first, because the site loads this page as the default. :return: None. """ bp.go_to_population() assert bp.population_displayed() bp.util.sleep(3)
def test_toggle_org_settings(self, bp: BasePage, op: OrganismPage): """ Tests closing the Organism Settings pop-up. :return: None. """ bp.go_to_organism() op.open_org_settings() assert op.org_settings_displayed() op.close_org_settings() bp.util.sleep(1) assert not op.org_settings_displayed()
def test_toggle_org_details(self, bp: BasePage, op: OrganismPage): """ Tests toggling the Details panel within the Organism page on and off. :return: None. """ bp.go_to_organism() op.open_org_details() assert op.org_details_displayed() op.close_org_details() assert not op.org_details_displayed() op.open_org_details() assert op.org_details_displayed()
def test_exp_run_controls(self, bp: BasePage, pp: PopulationPage): """ Tests that a simple experiment can be run and that running, pausing, and doing one update work as expected. :return: None. """ # Add @ancestor to dish. bp.add_ancestor_to_dish() # Run the experiment. bp.run_from_menu() bp.util.sleep(3, "Waiting for updates to occur.") # Assert that updates have occurred. assert pp.get_pop_current_update() > 0 assert pp.gr_get_pop_current_update() > 0 # Pause the experiment. bp.pause_from_menu() bp.util.sleep(1, "Making sure pause goes into effect.") # Get current update, wait a few seconds, assert it has not changed. current_update = pp.get_pop_current_update() bp.util.sleep(3, "Ensuring no updates occur after pause.") assert pp.get_pop_current_update() == current_update # Do one update bp.forward_from_menu() bp.util.sleep(1, "Making sure update has time to occur.") assert (pp.get_pop_current_update() - current_update) == 1
def test_toggle_pop_stats(self, bp: BasePage, pp: PopulationPage): """ Tests toggling the Population Statistics window on and off. :return: None. """ bp.go_to_population() pp.show_pop_stats() assert pp.pop_stats_displayed() pp.hide_pop_stats() assert not pp.pop_stats_displayed() pp.show_pop_stats() assert pp.pop_stats_displayed()
def class_setup(self, request, bp: BasePage): """ Sets up class prior to run. Adds necessary variables to the class and waits for the splash screen to go away. Also performs any necessary cleanup of the objects it instantiates after testing is completed. :return: None. """ # Wait for splash screen to go away bp.wait_until_splash_gone() yield # Cleanup of logger object. bp.close_logger()
def test_toggle_env_settings(self, bp: BasePage, pp: PopulationPage): """ Tests toggling the Environmental Settings panel on and off. :return: None. """ bp.go_to_population() pp.show_env_settings() assert pp.env_settings_displayed() assert not pp.grid_displayed() pp.hide_env_settings() assert not pp.env_settings_displayed() assert pp.grid_displayed() pp.show_env_settings() assert pp.env_settings_displayed() assert not pp.grid_displayed()
def test_check_calcs(self, bp: BasePage, pp: PopulationPage): """ Tests calculation of avg fitness, offspring cost, and energy acq. rate (as well as # of viable orgs). :return: None. """ bp.add_ancestor_to_dish() pp.run_from_pop() bp.util.sleep(10, "Waiting for experiment to run for a while.") pp.pause_from_pop() bp.util.sleep(10, "Waiting for pause.") calculated_values = pp.calculate_pop_averages() assert calculated_values[0] == pp.get_pop_current_viable() assert abs(calculated_values[1] - pp.get_pop_avg_fit()) < 0.2 assert abs(calculated_values[2] - pp.get_pop_avg_offspring_cost()) < 0.2 assert abs(calculated_values[3] - pp.get_pop_avg_energy_rate()) < 0.2
def closing_assertions(self, class_setup, bp: BasePage): """ Performs basic assertions that should evaluate to True after every test (e.g. crash report not displayed, etc.). :return: None. """ yield assert not bp.crash_report_displayed()
def test_org_rep_ctrl_functionality(self, bp: BasePage, op: OrganismPage): """ Tests that the controls for Organism Reproduction work as intended once an organism is loaded into the dish. :return: None. """ # Put ancestor in organism view op.go_to_organism() bp.click_freezer_item("@ancestor") bp.add_org_to_org_view() # Wait for ancestor to be in org view, ensure initial values sensible. op.wait_until_org_controls_enabled() assert op.get_cycle() == 0 # Test that forward and back options work. op.forward_org_rep() assert op.get_cycle() == 1 op.back_org_rep() assert op.get_cycle() == 0 # Test that running works. op.run_org_rep() op.util.sleep(1) assert op.get_cycle() > 0 # Test that pausing works. op.stop_org_rep() cycle = op.get_cycle() op.util.sleep(1) assert op.get_cycle() == cycle # Test that End goes to end of reproduction. op.end_org_rep() assert op.get_cycle() == 189 # Test that Reset goes back to 0. op.reset_org_rep() assert op.get_cycle() == 0
def test_input_dishsize_str(self, bp: BasePage, pp: PopulationPage): """ Tests that crashes and unexpected behaviors do not occur if a non-numeric string is given to the dish size boxes. :return: None. """ # Edit dish size with string values. pp.show_env_settings() pp.edit_dish_cols("sample text") pp.hide_env_settings() assert pp.check_size_cells_error() # Add an organism to the experiment and try to run it. bp.add_ancestor_to_dish() pp.run_from_pop() # Wait for a short period so that response to run attempt occurs. bp.util.sleep(3)
def set_up(request, username, password): df = DriverFactory("Chrome") driver = df.launch_browser() if request.cls is not None: request.cls.driver = driver request.cls.bp = BasePage(driver) request.cls.lp = LoginPage(driver) request.cls.hp = HomePage(driver) request.cls.username = username request.cls.password = password yield driver driver.quit()
def test_input_mut_over_thousand(self, bp: BasePage, pp: PopulationPage): """ Tests that crashes and unexpected behavior do not occur if bad input is given to the population mutation rate boxes. :return: None. """ # Edit pop mutation rate with value over 1000. pp.show_env_settings() pp.edit_mut_rate("5000") pp.hide_env_settings() assert pp.check_mutation_rate_error() # Add an organism to the dish and try to run it. bp.click_freezer_item("@ancestor") bp.add_org_to_exp() pp.run_from_pop() # Wait a short period so that response to run attempt occurs. bp.util.sleep(3)
def test_pop_stats_sanity_ancestor(self, bp: BasePage, pp: PopulationPage): """ Tests that running an experiment with @ancestor for a brief period of time does not lead to any unexpected values in the population statistics window. :return: None. """ # Add @ancestor to dish. bp.add_ancestor_to_dish() # Run the experiment for a while, then pause it. bp.run_from_menu() bp.util.sleep(15, "Waiting for updates to occur.") bp.pause_from_menu() bp.util.sleep(1, "Waiting for pause to take affect.") # Test that population stats are valid. assert pp.get_pop_current_update() > 0 assert pp.get_pop_num_orgs() > 1 assert pp.get_pop_avg_fit() >= 0.0 assert pp.get_pop_avg_energy_rate() > 0 assert pp.get_pop_avg_offspring_cost() > 0 assert pp.get_pop_avg_age() >= 0
def test_org_rep_stats_functionality(self, bp: BasePage, op: OrganismPage): """ Tests that the controls for Organism Reproduction work as intended when an organism that can perform all functions is added to the dish. :return: None. """ # Put all_functions in organism view op.go_to_organism() bp.click_freezer_item("@all_functions") bp.add_org_to_org_view() # Wait for ancestor to be in org view, ensure initial values sensible. op.wait_until_org_controls_enabled() # Make sure at beginning of reproduction, all stats 0. assert op.get_org_num_not_performed() == 0 assert op.get_org_num_nan_performed() == 0 assert op.get_org_num_and_performed() == 0 assert op.get_org_num_orn_performed() == 0 assert op.get_org_num_oro_performed() == 0 assert op.get_org_num_ant_performed() == 0 assert op.get_org_num_nor_performed() == 0 assert op.get_org_num_xor_performed() == 0 assert op.get_org_num_equ_performed() == 0 # Go to end of reproduction. op.end_org_rep() # Assert that all functions have been performed. assert op.get_org_num_not_performed() == 1 assert op.get_org_num_nan_performed() == 1 assert op.get_org_num_and_performed() == 1 assert op.get_org_num_orn_performed() == 1 assert op.get_org_num_oro_performed() == 1 assert op.get_org_num_ant_performed() == 1 assert op.get_org_num_nor_performed() == 1 assert op.get_org_num_xor_performed() == 1 assert op.get_org_num_equ_performed() == 1
def test_export_graphics(self, bp: BasePage): """ Tests that the "Export Graphics" option in the File tab works as expected. :return: None. """ assert not bp.export_graphics_dialog_displayed() bp.export_graphics() assert bp.export_graphics_dialog_displayed() bp.close_export_graphics_dialog() assert not bp.export_graphics_dialog_displayed()
def __init__(self): BasePage.__init__(self) self.name = ( By.CSS_SELECTOR, 'div.form-group:nth-child(1) > div:nth-child(2) > input:nth-child(1)' ) self.tel = (By.CSS_SELECTOR, '.isPhone') self.certtype = ( By.CSS_SELECTOR, 'div.form-group:nth-child(2) > div:nth-child(4) > select:nth-child(1)' ) self.certno = (By.CSS_SELECTOR, '#certNoInput') self.dept = (By.CSS_SELECTOR, '#view_DEPTID') self.dept0 = ( By.XPATH, '/html/body/div[9]/div/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[1]/img' ) self.duty = ( By.CSS_SELECTOR, 'div.form-group:nth-child(5) > div:nth-child(4) > select:nth-child(1)' ) self.save_btn = (By.CSS_SELECTOR, '#submit')
def test_input_dishsize_zero( self, bp: BasePage, pp: PopulationPage, ): """ Tests that crashes and unexpected behaviors do not occur if a dish size dimension is set to 0. :return: None. """ # Edit dish size with value zero. pp.show_env_settings() pp.edit_dish_cols("0") pp.hide_env_settings() assert pp.check_size_cells_error() # Add an organism to the experiment and try to run it. bp.add_ancestor_to_dish() pp.run_from_pop() # Wait for a short period so that response to run attempt occurs. bp.util.sleep(3)
def test_about_page(self, bp: BasePage): """ Tests that the about page works properly. :return: None. """ bp.open_avida_ed_about() assert bp.avida_ed_about_displayed() bp.close_avida_ed_about() assert not bp.avida_ed_about_displayed()
def test_pop_stats_sanity_allfxns(self, bp: BasePage, pp: PopulationPage): """ Tests that running an experiment with @all_functions does not create unexpected values in pop. stats window and that this window shows that all of the functions have been performed at least once (which should always happen because the starting org can perform all functions). :return: None. """ # Add @all_functions to dish. bp.add_all_functions_to_dish() # Run the experiment for a while, then pause it. bp.run_from_menu() bp.util.sleep(15, "Waiting for updates to occur.") bp.pause_from_menu() bp.util.sleep(1, "Waiting for pause to take affect.") # Test that population stats are valid. assert pp.get_pop_current_update() > 0 assert pp.get_pop_num_orgs() > 1 assert pp.get_pop_avg_fit() >= 0.0 assert pp.get_pop_avg_energy_rate() > 0 assert pp.get_pop_avg_offspring_cost() > 0 assert pp.get_pop_avg_age() >= 0 # Test that all functions have occurred. assert pp.get_pop_num_performing_not() > 0 assert pp.get_pop_num_performing_nan() > 0 assert pp.get_pop_num_performing_and() > 0 assert pp.get_pop_num_performing_orn() > 0 assert pp.get_pop_num_performing_oro() > 0 assert pp.get_pop_num_performing_ant() > 0 assert pp.get_pop_num_performing_nor() > 0 assert pp.get_pop_num_performing_xor() > 0 assert pp.get_pop_num_performing_equ() > 0
def __init__(self): self.ini_element = ELEMENT_INI.one_button_wall_switch self.ini_element_file_path = ELEMENT_INI_PATH.control BasePage.__init__(self)
def __init__(self): BasePage.__init__(self) #获取父类的浏览器对象 self.username = (By.ID, 'username') self.password = (By.ID, 'plainpwd') self.checkcode = (By.ID, 'captcha') self.loginbtn = (By.ID, 'gologin')