Skip to content

Commit d4a437b

Browse files
committed
Added test for collaboration in editor.
Testing basic functionality of the editor when collaboration is enabled. Tests can run in Firefox only due to its support for alert dialogs.
1 parent 8be5370 commit d4a437b

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

bin/seleniumbender.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def run(self, operation, test=None, libraries=None):
4141
self.staging()
4242
elif operation == 'delete':
4343
self.delete()
44+
elif operation == 'collaboration':
45+
self.collaboration()
4446

4547
def run_command(self, command):
4648
command = ' '.join(command)
@@ -158,6 +160,12 @@ def delete(self):
158160
if retval != 0:
159161
self.retval = retval
160162

163+
def collaboration(self):
164+
command = self.create_command('collaboration')
165+
retval = self.run_command(command)
166+
if retval != 0:
167+
self.retval = retval
168+
161169
OPERATIONS = {
162170
'common':'\tTest site common functionality',
163171
'libraries': 'Visit all libraries and their examples',
@@ -167,7 +175,8 @@ def delete(self):
167175
'noplugin': 'Run tests without app/plugin installed',
168176
'walkthrough': 'Run tests for walkthrough',
169177
'staging': '\tRun tests for staging only',
170-
'delete': '\tDelete all sketches from test user'
178+
'delete': '\tDelete all sketches from test user',
179+
'collaboration': 'Run tests for collaboration'
171180
}
172181

173182
TARGETS = {

tests/collaboration/__init__.py

Whitespace-only changes.
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import pytest
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.common.keys import Keys
4+
from selenium.webdriver.support.ui import WebDriverWait
5+
from selenium.webdriver.support import expected_conditions
6+
from selenium.webdriver.common.action_chains import ActionChains
7+
from selenium.webdriver.common.alert import Alert
8+
from codebender_testing.utils import SeleniumTestCase
9+
from codebender_testing.config import TIMEOUT
10+
import time
11+
12+
TEST_SKETCH = 'test_collaboration'
13+
TEST_FILE = 'test.h'
14+
TEST_EMPTY_FILE = 'empty.h'
15+
TEST_RENAME_FILE = 'rename.h'
16+
TEST_RENAMED_FILE = 'renamed.h'
17+
TEST_INPUT = '// test input'
18+
19+
class TestCollaboration(SeleniumTestCase):
20+
''' Opens a new tab in the browser '''
21+
def open_tab(self, url):
22+
self.execute_script('window.open("{}")'.format(url))
23+
24+
''' Closes current tab in the browser '''
25+
def close_tab(self):
26+
self.execute_script('window.close()')
27+
28+
''' Switches between tabs in the browser '''
29+
def switch_window(self, index):
30+
window = self.driver.window_handles[index]
31+
self.driver.switch_to.window(window)
32+
33+
@pytest.fixture(scope="class", autouse=True)
34+
def create_test_project(self, tester_login):
35+
"""Makes sure we are logged in and have a project open before
36+
performing any of these tests."""
37+
self.create_sketch('public' , TEST_SKETCH, '')
38+
39+
def test_open_tab(self):
40+
self.sketch_url = self.execute_script('return location.href')
41+
self.open_tab(self.sketch_url)
42+
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
43+
expected_conditions.invisibility_of_element_located(
44+
(By.CSS_SELECTOR, "#editor-loading-screen")
45+
)
46+
)
47+
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
48+
expected_conditions.element_to_be_clickable(
49+
(By.CSS_SELECTOR, "#editor_heading_project_name")
50+
)
51+
)
52+
53+
def test_create_file(self):
54+
self.switch_window(0)
55+
self.create_file(TEST_FILE)
56+
57+
def test_check_created_file(self):
58+
self.switch_window(1)
59+
test_file = self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"]'.format(TEST_FILE))
60+
filename = test_file.text.strip()
61+
assert filename == TEST_FILE
62+
test_file.click()
63+
self.execute_script('editor.aceEditor.setValue("{}");'.format(TEST_INPUT), 'editor')
64+
65+
def test_check_contents_change(self):
66+
self.switch_window(0)
67+
test_input = self.execute_script('return editor.aceEditor.getValue();')
68+
assert TEST_INPUT == test_input
69+
70+
def test_create_and_delete_file(self):
71+
self.switch_window(0)
72+
self.create_file(TEST_EMPTY_FILE)
73+
self.switch_window(1)
74+
test_file = self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"]'.format(TEST_EMPTY_FILE))
75+
filename = test_file.text.strip()
76+
assert filename == TEST_EMPTY_FILE
77+
test_file.click()
78+
self.execute_script('editor.aceEditor.setValue("{}");'.format(TEST_INPUT), 'editor')
79+
self.remove_file(filename)
80+
self.switch_window(0)
81+
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
82+
expected_conditions.alert_is_present()
83+
)
84+
Alert(self.driver).dismiss()
85+
86+
def test_check_deleted_file(self):
87+
self.switch_window(0)
88+
deleted_file = self.driver.find_elements_by_css_selector('#files_list .filelist[data-name="{}"]'.format(TEST_EMPTY_FILE))
89+
assert len(deleted_file) == 0
90+
self.create_file(TEST_EMPTY_FILE)
91+
empty_contents = self.execute_script('return editor.aceEditor.getValue();', 'editor')
92+
assert empty_contents == ''
93+
94+
def test_rename_file(self):
95+
self.switch_window(1)
96+
self.create_file(TEST_RENAME_FILE)
97+
self.execute_script('editor.aceEditor.setValue("int a = 1;");', 'editor')
98+
self.execute_script('editor.aceEditor.session.selection.moveCursorToPosition({row: 0, column: 3}); editor.aceEditor.session.selection.clearSelection();', 'editor')
99+
self.switch_window(0)
100+
self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"]'.format(TEST_RENAME_FILE)).click()
101+
self.rename_file(TEST_RENAME_FILE, TEST_RENAMED_FILE)
102+
self.switch_window(1)
103+
self.get_element(By.CSS_SELECTOR, '#files_list .filelist[data-name="{}"]'.format(TEST_RENAMED_FILE))
104+
105+
def test_remove_sketch(self):
106+
self.switch_window(1)
107+
self.remove_sketch_editor()
108+
self.switch_window(0)
109+
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
110+
expected_conditions.alert_is_present()
111+
)
112+
Alert(self.driver).dismiss()
113+
self.logout()

0 commit comments

Comments
 (0)