-
Notifications
You must be signed in to change notification settings - Fork 5
Frontend js unit tests #676 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
dc9c4d6
8ab2bad
a9fdec2
8e68b45
e9560a4
c36d6bf
a331a1f
b04cdd2
ca761f9
5d85a87
f40629d
fdd54d9
04644d4
458eb85
1a058b5
2cca710
d84b4da
b3d143c
5f3db1d
e2491ec
8740785
0586f9d
0fa143b
b881a82
211cb29
9fec384
b5c8aaa
3f32f26
45e3c43
97eb8e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| from codebender_testing.utils import SeleniumTestCase | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support.ui import Select | ||
| from codebender_testing import config | ||
| from codebender_testing.config import STAGING_SITE_URL | ||
|
||
| from selenium.webdriver.common.action_chains import ActionChains | ||
| import os | ||
|
||
| import time | ||
| import pytest | ||
|
||
|
|
||
| class TestEditor(SeleniumTestCase): | ||
|
|
||
| def test_editor(self): | ||
| self.driver.implicitly_wait(30) | ||
|
||
| driver = self.driver | ||
| self.open("/") | ||
| #Login and visit the new home page. | ||
| credentials = { | ||
| 'username': os.environ.get('CODEBENDER_TEST_USER'), | ||
| 'password': os.environ.get('CODEBENDER_TEST_PASS'), | ||
| } | ||
| driver.find_element_by_id("login_btn").click() | ||
|
||
| driver.find_element_by_id("username").clear() | ||
| driver.find_element_by_id("username").send_keys(credentials['username']) | ||
| driver.find_element_by_id("password").clear() | ||
| driver.find_element_by_id("password").send_keys(credentials['password']) | ||
| driver.find_element_by_id("_submit").click() | ||
|
|
||
| assert driver.find_element_by_id("private-sketches-counter").text=="0" | ||
|
||
| assert driver.find_element_by_id("public-sketches-counter").text=="0" | ||
|
||
|
|
||
| #Create 1 public sketches | ||
|
||
| driver.find_element_by_id("create_sketch_btn").click() | ||
|
||
| driver.find_element_by_id("create-sketch-modal-action-button").click() | ||
| self.get_element(By.ID, "save") | ||
| driver.find_element_by_id("logo_small").click() | ||
|
|
||
| #Check that the sketch was created | ||
| assert driver.find_element_by_id("public-sketches-counter").text=="1" | ||
|
||
|
|
||
| #Check that when you click on the sketch, sketch opens in editor. | ||
| driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
|
||
| assert self.get_element(By.ID, "cb_cf_flash_btn").text == "Run on Arduino" | ||
|
|
||
| #double click the earth icon on the left of its title to make it private . | ||
| #Project privacy settings successfully changed! | ||
| changeButton = self.get_element(By.XPATH, "//span[@id='editor_heading_privacy_icon']/i") | ||
|
||
| actions = ActionChains(driver) | ||
| actions.move_to_element(changeButton) | ||
| actions.double_click(changeButton) | ||
| actions.perform() | ||
| self.get_element(By.ID, "logo_small").click() | ||
| assert self.get_element(By.ID, "public-sketches-counter").text=="0" | ||
|
||
| assert self.get_element(By.ID, "private-sketches-counter").text=="1" | ||
|
||
|
|
||
| driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
| changeButton = self.get_element(By.XPATH, "//span[@id='editor_heading_privacy_icon']/i") | ||
| actions = ActionChains(driver) | ||
| actions.move_to_element(changeButton) | ||
| actions.double_click(changeButton) | ||
| actions.perform() | ||
|
|
||
| #Go to a sketch in editor and change the short description | ||
| #Rename the sketch from the editor | ||
| driver.find_element_by_xpath("//div[2]/a/span").click() | ||
|
||
| driver.find_element_by_xpath("//div[6]/div[2]/div/div/input").clear() | ||
| driver.find_element_by_xpath("//div[6]/div[2]/div/div/input").send_keys("test") | ||
| driver.find_element_by_xpath("//div[3]/button[2]").click() | ||
| #assert self.get_element(By.XPATH, "//div/pre").text == "Name successfully changed!" | ||
|
||
| driver.find_element_by_xpath("//div[6]/div/button").click() | ||
|
|
||
| #Go to a sketch in editor and click the Clone button | ||
| driver.find_element_by_id("create_sketch_btn").click() | ||
| driver.find_element_by_id("create-sketch-modal-action-button").click() | ||
| driver.find_element_by_id("logo_small").click() | ||
| driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
| driver.find_element_by_id("clone_btn").click() | ||
| driver.find_element_by_id("logo_small").click() | ||
|
|
||
| #Go to a sketch in editor and add a file/Rename file/delete a file/ | ||
|
||
| driver.find_element_by_id("newfile").click() | ||
| driver.find_element_by_id("createfield").clear() | ||
| driver.find_element_by_id("createfield").send_keys("test") | ||
| driver.find_element_by_id("createbutton").click() | ||
| self.get_element(By.XPATH, "//ul[@id='files_list']/li[2]/a[3]/i").click() | ||
| driver.find_element_by_id("newFilename").clear() | ||
| driver.find_element_by_id("newFilename").send_keys("testA") | ||
| driver.find_element_by_id("renamebutton").click() | ||
| self.get_element(By.XPATH, "//ul[@id='files_list']/li[2]/a[2]/i").click() | ||
| self.get_element(By.XPATH, "//div[5]/div[3]/a[2]").click() | ||
| driver.find_element_by_id("logo_small").click() | ||
|
|
||
| class TestDeleteAllSketches(SeleniumTestCase): | ||
|
|
||
| @pytest.mark.requires_url(STAGING_SITE_URL) | ||
|
||
| def test_delete(self, tester_login): | ||
|
||
| try: | ||
| sketches = self.find_all('#project_list > li .sketch-block-title > a') | ||
| projects = [] | ||
| for sketch in sketches: | ||
| projects.append(sketch.text) | ||
| for project in projects: | ||
| self.delete_project(project) | ||
| except: | ||
| print 'No sketches found' | ||
|
|
||
|
|
||
| self.logout() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| from codebender_testing.utils import SeleniumTestCase | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support.ui import Select | ||
| from codebender_testing import config | ||
| from codebender_testing.config import STAGING_SITE_URL | ||
|
||
| import os | ||
|
||
| import time | ||
| import pytest | ||
|
|
||
| class TestInsideSketchBlock(SeleniumTestCase): | ||
|
|
||
| def test_inside_sketch_block(self): | ||
| self.driver.implicitly_wait(30) | ||
|
||
| driver = self.driver | ||
| self.open("/") | ||
| #Login and visit the new home page. | ||
| credentials = { | ||
| 'username': os.environ.get('CODEBENDER_TEST_USER'), | ||
| 'password': os.environ.get('CODEBENDER_TEST_PASS'), | ||
| } | ||
| driver.find_element_by_id("login_btn").click() | ||
|
||
| driver.find_element_by_id("username").clear() | ||
| driver.find_element_by_id("username").send_keys(credentials['username']) | ||
| driver.find_element_by_id("password").clear() | ||
| driver.find_element_by_id("password").send_keys(credentials['password']) | ||
| driver.find_element_by_id("_submit").click() | ||
|
|
||
| assert driver.find_element_by_id("public-sketches-counter").text=="0" | ||
|
||
|
|
||
| #Create 1 public sketches | ||
| driver.find_element_by_id("create_sketch_btn").click() | ||
|
||
| driver.find_element_by_id("create-sketch-modal-action-button").click() | ||
| self.get_element(By.ID, "save") | ||
| driver.find_element_by_id("logo_small").click() | ||
| #Check that the sketch was created | ||
| assert driver.find_element_by_id("public-sketches-counter").text=="1" | ||
|
||
|
|
||
| #Check that when you click on the sketch, sketch opens in editor. | ||
| #Create a sketch using the Create button and go back to homepage. | ||
| #Sketch should say Created instead of Modified. | ||
| #Go back to the sketch previously created and do some changes. | ||
| #Save it and go back to homepage. Sketch should say Modified instead of Created. | ||
| driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
| assert self.get_element(By.ID, "cb_cf_flash_btn").text == "Run on Arduino" | ||
| self.get_element(By.ID, "logo_small").click() | ||
| assert self.get_element(By.XPATH , "//div/a/span").text == "created a few seconds ago" | ||
|
|
||
| driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
| self.get_element(By.ID, "save").click() | ||
| self.get_element(By.ID, "logo_small").click() | ||
| assert self.get_element(By.XPATH , "//div/a/span").text == "modified a few seconds ago" | ||
|
|
||
| #Check the Share button. | ||
| driver.find_element_by_xpath("//div[4]/a/i").click() | ||
| driver.find_element_by_link_text("Share").click() | ||
| driver.find_element_by_link_text("Embed").click() | ||
| driver.find_element_by_link_text("Share").click() | ||
| assert self.get_element(By.XPATH , "//div[7]/div/h3").text == "Share your Sketch" | ||
| self.get_element(By.XPATH, "//div[@id='share-modal']/div/button").click() | ||
|
|
||
| #Check the clone sketch function. | ||
| #Click on Clone button and check that the sketch is cloned and opens in editor. | ||
| self.get_element(By.XPATH, "//div[4]/a[2]/i").click() | ||
| self.get_element(By.ID, "save").click() | ||
| self.get_element(By.ID, "logo_small").click() | ||
| self.get_element(By.XPATH, "//li/div/div/div[2]/a").click() | ||
| self.get_element(By.ID, "logo_small").click() | ||
|
|
||
| #Check that the file list of the sketch is at the bottom of the sketch block. | ||
| driver.find_element_by_id("newfile").click() | ||
| driver.find_element_by_id("createfield").clear() | ||
| driver.find_element_by_id("createfield").send_keys("test.h") | ||
| self.get_element(By.ID, "createbutton").click() | ||
| assert self.get_element(By.ID, "operation_output").text == "File successfully created." | ||
| driver.find_element_by_id("logo_small").click() | ||
|
|
||
| #Check that when a sketch has a short description, it appears at the section below the name, | ||
| driver.find_element_by_id("create_sketch_btn").click() | ||
| driver.find_element_by_id("create-sketch-modal-short-description").clear() | ||
| driver.find_element_by_id("create-sketch-modal-short-description").send_keys("Test") | ||
| driver.find_element_by_id("create-sketch-modal-action-button").click() | ||
| assert self.get_element(By.ID, "short-description").text == "Test" | ||
|
|
||
| #Ckeck that when a sketch has a short description does not appear at all. | ||
|
||
| driver.find_element_by_id("create_sketch_btn").click() | ||
| driver.find_element_by_id("create-sketch-modal-short-description").clear() | ||
| driver.find_element_by_id("create-sketch-modal-short-description").send_keys("TestTestTestTestTestTestTestTestTestTest") | ||
| driver.find_element_by_id("create-sketch-modal-action-button").click() | ||
| assert self.get_element(By.ID, "short-description").text == "TestTestTestTestTestTestTestTestTestTest" | ||
| driver.find_element_by_id("logo_small").click() | ||
|
|
||
| #Check the delete sketch fuction. | ||
| driver.find_element_by_xpath("//a[3]/i").click() | ||
| #Check that when the sketch is deleted the modal stays open showing the result of the deletion. | ||
|
||
| assert self.get_element(By.XPATH, "//div[5]/div/h3").text == "Are you sure you want to delete your sketch?" | ||
| driver.find_element_by_xpath("//div[4]/button").click() | ||
| driver.find_element_by_xpath("//div[4]/button[2]").click() | ||
|
|
||
| class TestDeleteAllSketches(SeleniumTestCase): | ||
|
|
||
| @pytest.mark.requires_url(STAGING_SITE_URL) | ||
| def test_delete(self, tester_login): | ||
| try: | ||
| sketches = self.find_all('#project_list > li .sketch-block-title > a') | ||
| projects = [] | ||
| for sketch in sketches: | ||
| projects.append(sketch.text) | ||
| for project in projects: | ||
| self.delete_project(project) | ||
| except: | ||
| print 'No sketches found' | ||
|
|
||
| self.logout() | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are more tests than the home page counters, maybe we should rename the parent directory
sketches_countersto a more descriptive name e.g.home_page