|
6 | 6 | from codebender_testing import config
|
7 | 7 | from codebender_testing.config import STAGING_SITE_URL
|
8 | 8 | from selenium.webdriver.common.action_chains import ActionChains
|
| 9 | +from selenium.webdriver.support import expected_conditions |
| 10 | +from codebender_testing.config import TIMEOUT |
| 11 | +from selenium.webdriver.support.ui import WebDriverWait |
9 | 12 | import os
|
10 | 13 | import time
|
11 | 14 | import pytest
|
12 | 15 |
|
13 | 16 | class TestSketchesCounters(SeleniumTestCase):
|
14 | 17 |
|
15 |
| - def test_sketches_counters(self): |
16 |
| - self.driver.implicitly_wait(30) |
17 |
| - driver = self.driver |
| 18 | + @pytest.fixture(scope="class", autouse=True) |
| 19 | + def open_user_home(self, tester_login): |
| 20 | + """Makes sure we are logged in and are at the user home page |
| 21 | + performing any of these tests.""" |
| 22 | + pass |
| 23 | + |
| 24 | + def test_create_sketch_modal(self): |
| 25 | + # Create a public project. |
| 26 | + createSketchBtn = self.get_element(By.ID, 'create_sketch_btn') |
| 27 | + createSketchBtn.click() |
| 28 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 29 | + expected_conditions.visibility_of_element_located( |
| 30 | + (By.CSS_SELECTOR, "#create-sketch-modal") |
| 31 | + ) |
| 32 | + ) |
| 33 | + createBtn = self.get_element( |
| 34 | + By.ID, 'create-sketch-modal-action-button') |
| 35 | + |
| 36 | + createdProject = self.get_element( |
| 37 | + By.ID, 'create-sketch-name').get_attribute('value') |
| 38 | + |
| 39 | + # Check that when the create sketch modal opens, |
| 40 | + # the sketch name input has focus. |
| 41 | + assert self.get_element(By.ID, 'create-sketch-name') == \ |
| 42 | + self.driver.switch_to.active_element |
| 43 | + |
| 44 | + # Check that when the input has focus and you press Enter, |
| 45 | + # the create sketch action is executed. |
| 46 | + self.get_element(By.ID, 'create-sketch-name').send_keys(Keys.ENTER) |
| 47 | + |
| 48 | + self.get_element(By.CSS_SELECTOR, '#create-sketch-modal-action-button .fa-spinner') |
| 49 | + |
| 50 | + # Check that during the sketch creation, |
| 51 | + # the sketch privacy radio buttons are disabled. |
| 52 | + publicRadioButton = self.get_element(By.CSS_SELECTOR, |
| 53 | + '#create-sketch-modal-type-controls [value="public"]') |
| 54 | + privateRadioButton = self.get_element(By.CSS_SELECTOR, |
| 55 | + '#create-sketch-modal-type-controls [value="private"]') |
| 56 | + assert publicRadioButton.get_attribute('disabled') |
| 57 | + assert privateRadioButton.get_attribute('disabled') |
| 58 | + |
| 59 | + WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until( |
| 60 | + expected_conditions.element_to_be_clickable( |
| 61 | + (By.CSS_SELECTOR, "#editor_heading_project_name") |
| 62 | + ) |
| 63 | + ) |
| 64 | + |
| 65 | + # Delete the created project. |
18 | 66 | self.open("/")
|
19 |
| - #Login and visit the new home page. |
20 |
| - credentials = { |
21 |
| - 'username': os.environ.get('CODEBENDER_TEST_USER'), |
22 |
| - 'password': os.environ.get('CODEBENDER_TEST_PASS'), |
23 |
| - } |
24 |
| - driver.find_element_by_id("login_btn").click() |
25 |
| - driver.find_element_by_id("username").clear() |
26 |
| - driver.find_element_by_id("username").send_keys(credentials['username']) |
27 |
| - driver.find_element_by_id("password").clear() |
28 |
| - driver.find_element_by_id("password").send_keys(credentials['password']) |
29 |
| - driver.find_element_by_id("_submit").click() |
30 |
| - |
31 |
| - assert driver.find_element_by_id("private-sketches-counter").text=="0" |
32 |
| - assert driver.find_element_by_id("public-sketches-counter").text=="0" |
33 |
| - |
34 |
| - #Create 1 public sketch |
35 |
| - driver.find_element_by_id("create_sketch_btn").click() |
36 |
| - #Check that when the create sketch modal opens, the sketch name input has focus |
37 |
| - |
38 |
| - driver.find_element_by_id("create-sketch-modal-action-button").click() |
39 |
| - self.get_element(By.ID, "save") |
40 |
| - driver.find_element_by_id("logo_small").click() |
41 |
| - |
42 |
| - |
43 |
| - #Check that when the input has focus and you press Enter, |
44 |
| - #the create sketch action is executed and the user is redirected into the new sketch in editor |
45 |
| - |
46 |
| - |
47 |
| -class TestDeleteAllSketches(SeleniumTestCase): |
48 |
| - |
49 |
| - @pytest.mark.requires_url(STAGING_SITE_URL) |
50 |
| - def test_delete(self, tester_login): |
51 |
| - try: |
52 |
| - sketches = self.find_all('#project_list > li .sketch-block-title > a') |
53 |
| - projects = [] |
54 |
| - for sketch in sketches: |
55 |
| - projects.append(sketch.text) |
56 |
| - for project in projects: |
57 |
| - self.delete_project(project) |
58 |
| - except: |
59 |
| - print 'No sketches found' |
60 |
| - |
61 |
| - self.logout() |
| 67 | + self.delete_project(createdProject) |
0 commit comments