|
20 | 20 | from selenium.webdriver.common.keys import Keys
|
21 | 21 | from selenium.webdriver.support import expected_conditions
|
22 | 22 | from selenium.webdriver.support.ui import WebDriverWait
|
| 23 | +from selenium.common.exceptions import TimeoutException |
23 | 24 |
|
24 | 25 | from codebender_testing.config import BASE_URL
|
25 | 26 | from codebender_testing.config import TIMEOUT
|
@@ -893,12 +894,16 @@ def create_sketch(self, privacy, name, description):
|
893 | 894 |
|
894 | 895 | createBtn = self.get_element(By.ID, 'create-sketch-modal-action-button')
|
895 | 896 | createBtn.click()
|
896 |
| - |
897 |
| - WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
898 |
| - expected_conditions.visibility_of_element_located( |
899 |
| - (By.CSS_SELECTOR, "#editor-loading-screen") |
| 897 | + # Added in try-except block because if the loading screen disappears too quickly |
| 898 | + # the explicit wait will through an exception |
| 899 | + try: |
| 900 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 901 | + expected_conditions.visibility_of_element_located( |
| 902 | + (By.CSS_SELECTOR, "#editor-loading-screen") |
| 903 | + ) |
900 | 904 | )
|
901 |
| - ) |
| 905 | + except TimeoutException: |
| 906 | + pass |
902 | 907 | WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
|
903 | 908 | expected_conditions.invisibility_of_element_located(
|
904 | 909 | (By.CSS_SELECTOR, "#editor-loading-screen")
|
@@ -1006,6 +1011,59 @@ def switch_into_iframe(self, url):
|
1006 | 1011 | iframe = self.driver.find_elements_by_tag_name('iframe')[index]
|
1007 | 1012 | self.driver.switch_to_frame(iframe)
|
1008 | 1013 |
|
| 1014 | + def create_file(self, filename): |
| 1015 | + """ Creates a file in editor """ |
| 1016 | + self.get_element(By.ID, 'newfile').click() |
| 1017 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1018 | + expected_conditions.visibility_of_element_located( |
| 1019 | + (By.ID, 'creationModal')) |
| 1020 | + ) |
| 1021 | + self.get_element(By.ID, 'createfield').send_keys(filename) |
| 1022 | + self.get_element(By.ID, 'createfield').send_keys(Keys.ENTER) |
| 1023 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1024 | + expected_conditions.invisibility_of_element_located( |
| 1025 | + (By.ID, 'creationModal')) |
| 1026 | + ) |
| 1027 | + |
| 1028 | + def remove_file(self, filename): |
| 1029 | + self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"] + .delete-file-button'.format(filename)).click() |
| 1030 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1031 | + expected_conditions.visibility_of_element_located( |
| 1032 | + (By.ID, 'filedeleteModal')) |
| 1033 | + ) |
| 1034 | + self.get_element(By.ID, 'filedeleteButton').click() |
| 1035 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1036 | + expected_conditions.invisibility_of_element_located( |
| 1037 | + (By.ID, 'filedeleteModal')) |
| 1038 | + ) |
| 1039 | + |
| 1040 | + def rename_file(self, old_filename, new_filename): |
| 1041 | + self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"] ~ .rename-file-button'.format(old_filename)).click() |
| 1042 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1043 | + expected_conditions.visibility_of_element_located( |
| 1044 | + (By.ID, 'filenameModal')) |
| 1045 | + ) |
| 1046 | + filename_input = self.get_element(By.ID, 'newFilename') |
| 1047 | + filename_input.clear() |
| 1048 | + filename_input.send_keys(new_filename) |
| 1049 | + filename_input.send_keys(Keys.ENTER) |
| 1050 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1051 | + expected_conditions.invisibility_of_element_located( |
| 1052 | + (By.ID, 'filenameModal')) |
| 1053 | + ) |
| 1054 | + |
| 1055 | + def remove_sketch_editor(self): |
| 1056 | + """ Removes the sketch from editor page """ |
| 1057 | + self.get_element(By.ID, 'delete').click() |
| 1058 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1059 | + expected_conditions.visibility_of_element_located( |
| 1060 | + (By.ID, 'deletionModal')) |
| 1061 | + ) |
| 1062 | + self.get_element(By.ID, 'deleteProjectButton').click() |
| 1063 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 1064 | + expected_conditions.visibility_of_element_located( |
| 1065 | + (By.ID, 'main-container')) |
| 1066 | + ) |
1009 | 1067 |
|
1010 | 1068 | class SeleniumTestCase(CodebenderSeleniumBot):
|
1011 | 1069 | """Base class for all Selenium tests."""
|
|
0 commit comments