|
| 1 | +from codebender_testing.utils import SeleniumTestCase |
| 2 | +from selenium import webdriver |
| 3 | +from selenium.webdriver.common.by import By |
| 4 | +from selenium.webdriver.common.keys import Keys |
| 5 | +from selenium.webdriver.support.ui import Select |
| 6 | +from codebender_testing import config |
| 7 | +from codebender_testing.config import STAGING_SITE_URL |
| 8 | +import os |
| 9 | +import time |
| 10 | +import pytest |
| 11 | + |
| 12 | +class TestInsideSketchBlock(SeleniumTestCase): |
| 13 | + |
| 14 | + def test_inside_sketch_block(self): |
| 15 | + self.driver.implicitly_wait(30) |
| 16 | + driver = self.driver |
| 17 | + self.open("/") |
| 18 | + #Login and visit the new home page. |
| 19 | + credentials = { |
| 20 | + 'username': os.environ.get('CODEBENDER_TEST_USER'), |
| 21 | + 'password': os.environ.get('CODEBENDER_TEST_PASS'), |
| 22 | + } |
| 23 | + driver.find_element_by_id("login_btn").click() |
| 24 | + driver.find_element_by_id("username").clear() |
| 25 | + driver.find_element_by_id("username").send_keys(credentials['username']) |
| 26 | + driver.find_element_by_id("password").clear() |
| 27 | + driver.find_element_by_id("password").send_keys(credentials['password']) |
| 28 | + driver.find_element_by_id("_submit").click() |
| 29 | + |
| 30 | + assert driver.find_element_by_id("public-sketches-counter").text=="0" |
| 31 | + |
| 32 | + #Create 1 public sketches |
| 33 | + driver.find_element_by_id("create_sketch_btn").click() |
| 34 | + driver.find_element_by_id("create-sketch-modal-action-button").click() |
| 35 | + self.get_element(By.ID, "save") |
| 36 | + driver.find_element_by_id("logo_small").click() |
| 37 | + #Check that the sketch was created |
| 38 | + assert driver.find_element_by_id("public-sketches-counter").text=="1" |
| 39 | + |
| 40 | + #Check that when you click on the sketch, sketch opens in editor. |
| 41 | + #Create a sketch using the Create button and go back to homepage. |
| 42 | + #Sketch should say Created instead of Modified. |
| 43 | + #Go back to the sketch previously created and do some changes. |
| 44 | + #Save it and go back to homepage. Sketch should say Modified instead of Created. |
| 45 | + driver.find_element_by_xpath("//li/div/div/div[2]/a").click() |
| 46 | + assert self.get_element(By.ID, "cb_cf_flash_btn").text == "Run on Arduino" |
| 47 | + self.get_element(By.ID, "logo_small").click() |
| 48 | + assert self.get_element(By.XPATH , "//div/a/span").text == "created a few seconds ago" |
| 49 | + |
| 50 | + driver.find_element_by_xpath("//li/div/div/div[2]/a").click() |
| 51 | + self.get_element(By.ID, "save").click() |
| 52 | + self.get_element(By.ID, "logo_small").click() |
| 53 | + assert self.get_element(By.XPATH , "//div/a/span").text == "modified a few seconds ago" |
| 54 | + |
| 55 | + #Check the Share button. |
| 56 | + driver.find_element_by_xpath("//div[4]/a/i").click() |
| 57 | + driver.find_element_by_link_text("Share").click() |
| 58 | + driver.find_element_by_link_text("Embed").click() |
| 59 | + driver.find_element_by_link_text("Share").click() |
| 60 | + assert self.get_element(By.XPATH , "//div[7]/div/h3").text == "Share your Sketch" |
| 61 | + self.get_element(By.XPATH, "//div[@id='share-modal']/div/button").click() |
| 62 | + |
| 63 | + #Check the clone sketch function. |
| 64 | + #Click on Clone button and check that the sketch is cloned and opens in editor. |
| 65 | + self.get_element(By.XPATH, "//div[4]/a[2]/i").click() |
| 66 | + self.get_element(By.ID, "save").click() |
| 67 | + self.get_element(By.ID, "logo_small").click() |
| 68 | + self.get_element(By.XPATH, "//li/div/div/div[2]/a").click() |
| 69 | + self.get_element(By.ID, "logo_small").click() |
| 70 | + |
| 71 | + #Check that the file list of the sketch is at the bottom of the sketch block. |
| 72 | + driver.find_element_by_id("newfile").click() |
| 73 | + driver.find_element_by_id("createfield").clear() |
| 74 | + driver.find_element_by_id("createfield").send_keys("test.h") |
| 75 | + self.get_element(By.ID, "createbutton").click() |
| 76 | + assert self.get_element(By.ID, "operation_output").text == "File successfully created." |
| 77 | + driver.find_element_by_id("logo_small").click() |
| 78 | + |
| 79 | + #Check that when a sketch has a short description, it appears at the section below the name, |
| 80 | + driver.find_element_by_id("create_sketch_btn").click() |
| 81 | + driver.find_element_by_id("create-sketch-modal-short-description").clear() |
| 82 | + driver.find_element_by_id("create-sketch-modal-short-description").send_keys("Test") |
| 83 | + driver.find_element_by_id("create-sketch-modal-action-button").click() |
| 84 | + assert self.get_element(By.ID, "short-description").text == "Test" |
| 85 | + |
| 86 | + #Ckeck that when a sketch has a short description does not appear at all. |
| 87 | + driver.find_element_by_id("create_sketch_btn").click() |
| 88 | + driver.find_element_by_id("create-sketch-modal-short-description").clear() |
| 89 | + driver.find_element_by_id("create-sketch-modal-short-description").send_keys("TestTestTestTestTestTestTestTestTestTest") |
| 90 | + driver.find_element_by_id("create-sketch-modal-action-button").click() |
| 91 | + assert self.get_element(By.ID, "short-description").text == "TestTestTestTestTestTestTestTestTestTest" |
| 92 | + driver.find_element_by_id("logo_small").click() |
| 93 | + |
| 94 | + #Check the delete sketch fuction. |
| 95 | + driver.find_element_by_xpath("//a[3]/i").click() |
| 96 | + #Check that when the sketch is deleted the modal stays open showing the result of the deletion. |
| 97 | + assert self.get_element(By.XPATH, "//div[5]/div/h3").text == "Are you sure you want to delete your sketch?" |
| 98 | + driver.find_element_by_xpath("//div[4]/button").click() |
| 99 | + driver.find_element_by_xpath("//div[4]/button[2]").click() |
| 100 | + |
| 101 | +class TestDeleteAllSketches(SeleniumTestCase): |
| 102 | + |
| 103 | + @pytest.mark.requires_url(STAGING_SITE_URL) |
| 104 | + def test_delete(self, tester_login): |
| 105 | + try: |
| 106 | + sketches = self.find_all('#project_list > li .sketch-block-title > a') |
| 107 | + projects = [] |
| 108 | + for sketch in sketches: |
| 109 | + projects.append(sketch.text) |
| 110 | + for project in projects: |
| 111 | + self.delete_project(project) |
| 112 | + except: |
| 113 | + print 'No sketches found' |
| 114 | + |
| 115 | + self.logout() |
0 commit comments