Skip to content

Commit a331a1f

Browse files
committed
Adding the correct file
1 parent c36d6bf commit a331a1f

File tree

3 files changed

+436
-0
lines changed

3 files changed

+436
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
from selenium.webdriver.common.action_chains import ActionChains
9+
import os
10+
import time
11+
import pytest
12+
13+
class TestEditor(SeleniumTestCase):
14+
15+
def test_editor(self):
16+
self.driver.implicitly_wait(30)
17+
driver = self.driver
18+
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 sketches
35+
driver.find_element_by_id("create_sketch_btn").click()
36+
driver.find_element_by_id("create-sketch-modal-action-button").click()
37+
self.get_element(By.ID, "save")
38+
driver.find_element_by_id("logo_small").click()
39+
40+
#Check that the sketch was created
41+
assert driver.find_element_by_id("public-sketches-counter").text=="1"
42+
43+
#Check that when you click on the sketch, sketch opens in editor.
44+
driver.find_element_by_xpath("//li/div/div/div[2]/a").click()
45+
assert self.get_element(By.ID, "cb_cf_flash_btn").text == "Run on Arduino"
46+
47+
#double click the earth icon on the left of its title to make it private .
48+
#Project privacy settings successfully changed!
49+
changeButton = self.get_element(By.XPATH, "//span[@id='editor_heading_privacy_icon']/i")
50+
actions = ActionChains(driver)
51+
actions.move_to_element(changeButton)
52+
actions.double_click(changeButton)
53+
actions.perform()
54+
self.get_element(By.ID, "logo_small").click()
55+
assert self.get_element(By.ID, "public-sketches-counter").text=="0"
56+
assert self.get_element(By.ID, "private-sketches-counter").text=="1"
57+
58+
driver.find_element_by_xpath("//li/div/div/div[2]/a").click()
59+
changeButton = self.get_element(By.XPATH, "//span[@id='editor_heading_privacy_icon']/i")
60+
actions = ActionChains(driver)
61+
actions.move_to_element(changeButton)
62+
actions.double_click(changeButton)
63+
actions.perform()
64+
65+
#Go to a sketch in editor and change the short description
66+
#Rename the sketch from the editor
67+
driver.find_element_by_xpath("//div[2]/a/span").click()
68+
driver.find_element_by_xpath("//div[6]/div[2]/div/div/input").clear()
69+
driver.find_element_by_xpath("//div[6]/div[2]/div/div/input").send_keys("test")
70+
driver.find_element_by_xpath("//div[3]/button[2]").click()
71+
#assert self.get_element(By.XPATH, "//div/pre").text == "Name successfully changed!"
72+
driver.find_element_by_xpath("//div[6]/div/button").click()
73+
74+
#Go to a sketch in editor and click the Clone button
75+
driver.find_element_by_id("create_sketch_btn").click()
76+
driver.find_element_by_id("create-sketch-modal-action-button").click()
77+
driver.find_element_by_id("logo_small").click()
78+
driver.find_element_by_xpath("//li/div/div/div[2]/a").click()
79+
driver.find_element_by_id("clone_btn").click()
80+
driver.find_element_by_id("logo_small").click()
81+
82+
#Go to a sketch in editor and add a file/Rename file/delete a file/
83+
driver.find_element_by_id("newfile").click()
84+
driver.find_element_by_id("createfield").clear()
85+
driver.find_element_by_id("createfield").send_keys("test")
86+
driver.find_element_by_id("createbutton").click()
87+
self.get_element(By.XPATH, "//ul[@id='files_list']/li[2]/a[3]/i").click()
88+
driver.find_element_by_id("newFilename").clear()
89+
driver.find_element_by_id("newFilename").send_keys("testA")
90+
driver.find_element_by_id("renamebutton").click()
91+
self.get_element(By.XPATH, "//ul[@id='files_list']/li[2]/a[2]/i").click()
92+
self.get_element(By.XPATH, "//div[5]/div[3]/a[2]").click()
93+
driver.find_element_by_id("logo_small").click()
94+
95+
class TestDeleteAllSketches(SeleniumTestCase):
96+
97+
@pytest.mark.requires_url(STAGING_SITE_URL)
98+
def test_delete(self, tester_login):
99+
try:
100+
sketches = self.find_all('#project_list > li .sketch-block-title > a')
101+
projects = []
102+
for sketch in sketches:
103+
projects.append(sketch.text)
104+
for project in projects:
105+
self.delete_project(project)
106+
except:
107+
print 'No sketches found'
108+
109+
110+
self.logout()
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

Comments
 (0)