-
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After removing the decorator this is unused so we should remove it. |
||
from selenium.webdriver.common.action_chains import ActionChains | ||
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused imports. |
||
import time | ||
import pytest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will become obsolete when the decorator is removed. |
||
|
||
class TestEditor(SeleniumTestCase): | ||
|
||
def test_editor(self): | ||
self.driver.implicitly_wait(30) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove implicitly_wait setup and replace all the driver.find_element_by_* calls with the get_element function of the class. This applies to all three tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the self.login() method in order to perform the login in all tests. |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space between the comparison operator. Also it maybe be better to just read the counters when you first visit the home page in order to get their initial state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
assert driver.find_element_by_id("public-sketches-counter").text=="0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space also here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
#Create 1 public sketches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sketches -> sketch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
driver.find_element_by_id("create_sketch_btn").click() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the self.create_sketch() method that it is already implemented. |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
#Check that when you click on the sketch, sketch opens in editor. | ||
driver.find_element_by_xpath("//li/div/div/div[2]/a").click() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should replace the x_path expressions with CSS selectors in order to be consistent when selecting elements from the DOM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the x_path expressions with CSS selectors:Done |
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, we should replace the x-path expression with a CSS selector. This applies to all used x-path expressions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using the change of the sketch privacy from the editor across the tests multiple times, it is better to implement this functionality as method of CodebenderSeleniumBot() class an call it from there. No need to repeat the same code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
assert self.get_element(By.ID, "private-sketches-counter").text=="1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace x-path expressions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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!" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After each editor operation we should check that the filelist of the sketch is updated in the home page. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The decorator will prevent the test case from running elsewhere besides staging. We should remove this. |
||
def test_delete(self, tester_login): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using the same functionality in all the tests, it is better to add it as a method in CodebenderSeleniumBot() class and call it from there. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will become obsolete after we remove the decorator. |
||
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused imports. |
||
import time | ||
import pytest | ||
|
||
class TestInsideSketchBlock(SeleniumTestCase): | ||
|
||
def test_inside_sketch_block(self): | ||
self.driver.implicitly_wait(30) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove implicit wait. |
||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for using the self.login() method. |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space between the comparison operator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
#Create 1 public sketches | ||
driver.find_element_by_id("create_sketch_btn").click() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for using the self.create_sketch() method. |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space. |
||
|
||
#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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment suggest something different from what these steps do. |
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment suggests that we should test the deletion result inside the modal. |
||
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() |
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_counters
to a more descriptive name e.g.home_page