|
| 1 | +from codebender_testing.utils import SeleniumTestCase |
| 2 | +from selenium import webdriver |
| 3 | +from selenium.webdriver.common.by import By |
| 4 | +from codebender_testing import config |
| 5 | +from selenium.webdriver.common.action_chains import ActionChains |
| 6 | +from selenium.webdriver.support.ui import WebDriverWait |
| 7 | +from selenium.webdriver.support import expected_conditions |
| 8 | +import pytest |
| 9 | + |
| 10 | + |
| 11 | +class TestSketchesCounters(SeleniumTestCase): |
| 12 | + |
| 13 | + @pytest.fixture(scope="class", autouse=True) |
| 14 | + def open_user_home(self, tester_login): |
| 15 | + """Makes sure we are logged in and are at the user home page |
| 16 | + performing any of these tests.""" |
| 17 | + pass |
| 18 | + |
| 19 | + def test_sketches_counters(self): |
| 20 | + driver = self.driver |
| 21 | + # Check that the counters: Public sketches (blue) and Private sketches |
| 22 | + # (purple) have the correct value (number of sketches of each category). |
| 23 | + |
| 24 | + assert self.get_element(By.ID, "private-sketches-counter").text=="0" |
| 25 | + assert self.get_element(By.ID,"public-sketches-counter").text=="0" |
| 26 | + |
| 27 | + # Check that the counter for private projects also appears at the Badges |
| 28 | + # section and has the correct value. |
| 29 | + privateProjects = self.get_element(By.ID, |
| 30 | + "available-private-sketches-counter").text |
| 31 | + assert self.get_element(By.ID, |
| 32 | + "privateProjectAvailableNumber").text == \ |
| 33 | + privateProjects.split('/')[0] |
| 34 | + |
| 35 | + # Check that the counter for available private sketches also appears at |
| 36 | + # the upload sketch modal (ino, zip, multiple zip) and at the create and |
| 37 | + # edit sketch modal. |
| 38 | + |
| 39 | + # Upload .ino. |
| 40 | + self.get_element(By.ID, "sketch-upload-button").click() |
| 41 | + self.get_element(By.ID, "upload-sketch-ino").click() |
| 42 | + assert self.get_element(By.ID, |
| 43 | + "upload-sketch-modal-available-private-sketches").text == \ |
| 44 | + privateProjects |
| 45 | + close_btn = self.get_element(By.CSS_SELECTOR, |
| 46 | + "#home-upload-sketch-modal .btn-danger") |
| 47 | + close_btn.click() |
| 48 | + # Wait for the modal to close. |
| 49 | + WebDriverWait(self.driver, 30).until( |
| 50 | + expected_conditions.invisibility_of_element_located( |
| 51 | + (By.CSS_SELECTOR, ".modal-backdrop fade") |
| 52 | + ) |
| 53 | + ) |
| 54 | + |
| 55 | + # Upload .zip. |
| 56 | + self.get_element(By.ID, "sketch-upload-button").click() |
| 57 | + self.get_element(By.ID, "upload-sketch-zip").click() |
| 58 | + assert self.get_element(By.ID, |
| 59 | + "upload-sketch-modal-available-private-sketches").text == \ |
| 60 | + privateProjects |
| 61 | + close_btn = self.get_element(By.CSS_SELECTOR, |
| 62 | + "#home-upload-sketch-modal .btn-danger") |
| 63 | + close_btn.click() |
| 64 | + # Wait for the modal to close. |
| 65 | + WebDriverWait(self.driver, 30).until( |
| 66 | + expected_conditions.invisibility_of_element_located( |
| 67 | + (By.CSS_SELECTOR, ".modal-backdrop fade") |
| 68 | + ) |
| 69 | + ) |
| 70 | + |
| 71 | + # Upload your sketch folder [.zip]. |
| 72 | + self.get_element(By.ID, "sketch-upload-button").click() |
| 73 | + self.get_element(By.ID, "upload-sketch-folder-zip").click() |
| 74 | + assert self.get_element(By.ID, |
| 75 | + "upload-sketch-modal-available-private-sketches").text == \ |
| 76 | + privateProjects |
| 77 | + close_btn = self.get_element(By.CSS_SELECTOR, |
| 78 | + "#home-upload-sketch-modal .btn-danger") |
| 79 | + close_btn.click() |
| 80 | + # Wait for the modal to close. |
| 81 | + WebDriverWait(self.driver, 30).until( |
| 82 | + expected_conditions.invisibility_of_element_located( |
| 83 | + (By.CSS_SELECTOR, ".modal-backdrop fade") |
| 84 | + ) |
| 85 | + ) |
| 86 | + |
| 87 | + # Create sketch modal. |
| 88 | + self.get_element(By.ID, "create_sketch_btn").click() |
| 89 | + assert self.get_element(By.ID, |
| 90 | + "create-sketch-modal-available-private-sketches").text == \ |
| 91 | + privateProjects |
| 92 | + close_btn = self.get_element(By.CSS_SELECTOR, |
| 93 | + "#create-sketch-modal .btn-danger") |
| 94 | + close_btn.click() |
| 95 | + WebDriverWait(self.driver, 30).until( |
| 96 | + expected_conditions.invisibility_of_element_located( |
| 97 | + (By.CSS_SELECTOR, ".modal-backdrop fade") |
| 98 | + ) |
| 99 | + ) |
| 100 | + |
| 101 | + # Create one public project. |
| 102 | + self.create_sketch('public' , 'publicSketch1', 'short description') |
| 103 | + self.open("/") |
| 104 | + |
| 105 | + # Check that public sketch number was increased from 0 to 1. |
| 106 | + assert self.get_element(By.ID, "public-sketches-counter").text=="1" |
| 107 | + |
| 108 | + # Create one private project. |
| 109 | + self.create_sketch('private' , 'privateSketch1', 'short description') |
| 110 | + self.open("/") |
| 111 | + |
| 112 | + # Check that private sketch number was increased from 0 to 1. |
| 113 | + assert self.get_element(By.ID, "private-sketches-counter").text=="1" |
| 114 | + |
| 115 | + # Check that the counter for available private projects that appears at |
| 116 | + # the Badges section has the correct value. |
| 117 | + |
| 118 | + private_sketches = self.get_element(By.ID, |
| 119 | + "available-private-sketches-counter").text |
| 120 | + assert self.get_element(By.ID, |
| 121 | + "privateProjectAvailableNumber").text == \ |
| 122 | + private_sketches.split('/')[0] |
| 123 | + |
| 124 | + # Check that the number of private and public projects is updated |
| 125 | + # each time that you make a change (change a sketch from public |
| 126 | + # to private and vice versa). |
| 127 | + editInfo = driver.find_element_by_css_selector( |
| 128 | + '#project_list li[data-name="publicSketch1"] \ |
| 129 | + .sketch-block-container .sketch-block-header \ |
| 130 | + .sketch-block-edit-info') |
| 131 | + hoverEditInfo = ActionChains(driver).move_to_element(editInfo).perform() |
| 132 | + editInfoClick = driver.find_element_by_css_selector( |
| 133 | + '#project_list li[data-name="publicSketch1"] \ |
| 134 | + .sketch-block-container .sketch-block-header \ |
| 135 | + .sketch-block-edit-info a') |
| 136 | + editInfoClick.click() |
| 137 | + # Change project from public to private. |
| 138 | + privateRadioButton = self.get_element(By.CSS_SELECTOR, |
| 139 | + '#edit-sketch-modal-type-controls [value="private"]') |
| 140 | + privateRadioButton.click() |
| 141 | + # Click the Save button. |
| 142 | + save_btn = self.get_element(By.CSS_SELECTOR, |
| 143 | + "#edit-sketch-modal .btn-success") |
| 144 | + save_btn.click() |
| 145 | + # Wait for the modal to close. |
| 146 | + WebDriverWait(self.driver, 30).until( |
| 147 | + expected_conditions.invisibility_of_element_located( |
| 148 | + (By.CSS_SELECTOR, "#edit-sketch-modal") |
| 149 | + ) |
| 150 | + ) |
| 151 | + # Check public and private projects counters. |
| 152 | + assert self.get_element(By.ID, "private-sketches-counter").text=="2" |
| 153 | + assert self.get_element(By.ID, "public-sketches-counter").text=="0" |
| 154 | + |
| 155 | + editInfo = driver.find_element_by_css_selector( |
| 156 | + '#project_list li[data-name="publicSketch1"] \ |
| 157 | + .sketch-block-container .sketch-block-header \ |
| 158 | + .sketch-block-edit-info') |
| 159 | + hoverEditInfo = ActionChains(driver).move_to_element(editInfo).perform() |
| 160 | + editInfoClick = driver.find_element_by_css_selector( |
| 161 | + '#project_list li[data-name="publicSketch1"] \ |
| 162 | + .sketch-block-container .sketch-block-header \ |
| 163 | + .sketch-block-edit-info a') |
| 164 | + editInfoClick.click() |
| 165 | + # Change project from private to public. |
| 166 | + publicRadioButton = self.get_element(By.CSS_SELECTOR, |
| 167 | + '#edit-sketch-modal-type-controls [value="public"]') |
| 168 | + publicRadioButton.click() |
| 169 | + # Click the Save button. |
| 170 | + save_btn = self.get_element(By.CSS_SELECTOR, |
| 171 | + "#edit-sketch-modal .btn-success") |
| 172 | + save_btn.click() |
| 173 | + # Wait for the modal to close. |
| 174 | + WebDriverWait(self.driver, 30).until( |
| 175 | + expected_conditions.invisibility_of_element_located( |
| 176 | + (By.CSS_SELECTOR, "#edit-sketch-modal") |
| 177 | + ) |
| 178 | + ) |
| 179 | + # Check public and private projects counters. |
| 180 | + assert self.get_element(By.ID, "private-sketches-counter").text=="1" |
| 181 | + assert self.get_element(By.ID, "public-sketches-counter").text=="1" |
| 182 | + |
| 183 | + |
| 184 | + def test_sketch_filters(self): |
| 185 | + # Check that All, Public and Private buttons work, by clicking on each |
| 186 | + # of them and verifying hat the correct number of sketches appears. |
| 187 | + |
| 188 | + # Check "All sketches button". |
| 189 | + self.get_element(By.CSS_SELECTOR, |
| 190 | + '#filter-options label[data-filter="all"]').click() |
| 191 | + sketches = self.find_all('#project_list >li') |
| 192 | + assert len(sketches) == 2 |
| 193 | + |
| 194 | + # Check "Public button". |
| 195 | + self.get_element(By.CSS_SELECTOR, |
| 196 | + '#filter-options label[data-filter="public"]').click() |
| 197 | + sketches = self.find_all('#project_list >li .cb-icon-globe-inv') |
| 198 | + assert len(sketches) == 1 |
| 199 | + |
| 200 | + # Check "Private button". |
| 201 | + self.get_element(By.CSS_SELECTOR, |
| 202 | + '#filter-options label[data-filter="private"]').click() |
| 203 | + sketches = self.find_all('#project_list >li .fa-lock') |
| 204 | + assert len(sketches) == 1 |
| 205 | + |
| 206 | +class TestDeleteAllSketches(SeleniumTestCase): |
| 207 | + |
| 208 | + def test_delete(self, tester_login): |
| 209 | + try: |
| 210 | + sketches = self.find_all('#project_list > li \ |
| 211 | + .sketch-block-title > a') |
| 212 | + projects = [] |
| 213 | + for sketch in sketches: |
| 214 | + projects.append(sketch.text) |
| 215 | + for project in projects: |
| 216 | + self.delete_project(project) |
| 217 | + except: |
| 218 | + print 'No sketches found' |
| 219 | + |
| 220 | + self.logout() |
0 commit comments