Skip to content

Commit 8be5370

Browse files
committed
Added add/remove/rename file, remove sketch methods in CodebenderSeleniumBot class.
Will use the methods accross the tests.
1 parent 6555ef4 commit 8be5370

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

codebender_testing/utils.py

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from selenium.webdriver.common.keys import Keys
2121
from selenium.webdriver.support import expected_conditions
2222
from selenium.webdriver.support.ui import WebDriverWait
23+
from selenium.common.exceptions import TimeoutException
2324

2425
from codebender_testing.config import BASE_URL
2526
from codebender_testing.config import TIMEOUT
@@ -893,12 +894,16 @@ def create_sketch(self, privacy, name, description):
893894

894895
createBtn = self.get_element(By.ID, 'create-sketch-modal-action-button')
895896
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+
)
900904
)
901-
)
905+
except TimeoutException:
906+
pass
902907
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
903908
expected_conditions.invisibility_of_element_located(
904909
(By.CSS_SELECTOR, "#editor-loading-screen")
@@ -1006,6 +1011,59 @@ def switch_into_iframe(self, url):
10061011
iframe = self.driver.find_elements_by_tag_name('iframe')[index]
10071012
self.driver.switch_to_frame(iframe)
10081013

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+
)
10091067

10101068
class SeleniumTestCase(CodebenderSeleniumBot):
10111069
"""Base class for all Selenium tests."""

0 commit comments

Comments
 (0)