Skip to content

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dc9c4d6
Frontend js unit tests #676
penelopez Jun 22, 2016
8ab2bad
Fix any issues
penelopez Jun 27, 2016
a9fdec2
Updated script-Added new steps
penelopez Jun 28, 2016
8e68b45
Added new script for editor test cases
penelopez Jun 30, 2016
e9560a4
Added new steps
penelopez Jun 30, 2016
c36d6bf
Added news steps
penelopez Jul 1, 2016
a331a1f
Adding the correct file
penelopez Jul 4, 2016
b04cdd2
Removed folder sketches_counters which contained tests that didn't w…
Jul 29, 2016
ca761f9
Corrected typo in utils.py file.
Jul 29, 2016
5d85a87
Added test for filters and counters in user's homepage.
Jul 29, 2016
f40629d
Merge branch 'master' into frontend_js_unit_tests
Jul 29, 2016
fdd54d9
Check that sketch name is auto-generated as: Untitled Sketch CURRENT_…
Jul 29, 2016
04644d4
Check that when user creates a sketch he is redirected into the editor.
Jul 29, 2016
458eb85
Added missing import.
Jul 29, 2016
1a058b5
Check that Create btn is disabled when you create a sketch without a …
Jul 29, 2016
2cca710
Check that when user creates sketch with invalid name, error message …
Aug 2, 2016
d84b4da
Added short description tests inside Create Sketch modal.
Aug 9, 2016
b3d143c
Added test for "Cloned from" info that appear in homepage.
Aug 9, 2016
5f3db1d
Test that Create button works.
Aug 11, 2016
e2491ec
Test that when sketch short description is modified, modified msg app…
Aug 11, 2016
8740785
Test Share modal.
Aug 11, 2016
0586f9d
Tests clone button.
Aug 11, 2016
0fa143b
Updated utils functions change_name and change_name_editor.
Aug 11, 2016
b881a82
Added test for sketch rename inside editor.
Aug 11, 2016
211cb29
Added test that short_description is updated inside editor.
Aug 11, 2016
9fec384
Added test for file rename in editor.
Aug 11, 2016
b5c8aaa
Updated delete file function inside editor.
Aug 11, 2016
3f32f26
Reformatted code of test_sketch.py
Aug 11, 2016
45e3c43
Added function to change project privacy in editor.
Aug 11, 2016
97eb8e0
Added test that changes privacy in editor.
Aug 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
110 changes: 110 additions & 0 deletions tests/common/sketches_counters/test_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from codebender_testing.utils import SeleniumTestCase
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

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

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports.

import time
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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.
Check its implementation here: https://github.com/codebendercc/seleniumTests/blob/master/codebender_testing/utils.py#L333
Sorry for not mentioning this earlier.

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"
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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.
After creating / deleting sketches you can then check the counters values in order to test their behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert driver.find_element_by_id("public-sketches-counter").text=="0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space also here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


#Create 1 public sketches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sketches -> sketch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

driver.find_element_by_id("create_sketch_btn").click()
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
You can see its implementation here: https://github.com/codebendercc/seleniumTests/blob/master/codebender_testing/utils.py#L878

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Also, this x-path expression is really hard to follow since it does not contain any id or class of the selected element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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")
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert self.get_element(By.ID, "private-sketches-counter").text=="1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace x-path expressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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!"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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/
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
You should navigate to the home page each time to check that.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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):
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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()
115 changes: 115 additions & 0 deletions tests/common/sketches_counters/test_inside_sketch_block.py
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will become obsolete after we remove the decorator.

import os
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between the comparison operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

@freskoulix freskoulix Jul 4, 2016

Choose a reason for hiding this comment

The 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.
It doesn't seems implemented.

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()
Loading