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 1 commit
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
26 changes: 26 additions & 0 deletions tests/common/sketches_counters/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Pull Request:
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 the use .md extension in the Readme (e.g. Readme.md) so we can write in markdown the documentation.

https://github.com/codebendercc/codebender.cc/pull/676

Selenium_Test_Script

Homepage Test Caces:
test_sketches_counters.py : Check that the counters of the sketches are correct.


Login and visit the new home page.
Create 2 public sketches
Create 2 private sketches
Check that when the page loads, the loading screen appears and message "Loading the Sketches, please wait" is displayed.
Check that the counters:
Public sketches (blue) have the correct value.
Private sketches (purple) have the correct value.
Check that the counter for private projects also appears at the Badges section and has the correct value.
Check that if your account has private projects (e.g. 2) and all yor projects are public, counter for available private sketches should be 0/number of total private sketches(e.g. 0/2) and the link to the private sketches should be Add more.

Check that the number of private projects available is updated each time that you make a change (e.g from private to public and vice versa).
Change the privite sketch to public
Change the public to private




Empty file.
80 changes: 80 additions & 0 deletions tests/common/sketches_counters/test_sketches_counters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 selenium.common.exceptions import NoSuchElementException
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused import

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

from selenium.common.exceptions import NoAlertPresentException
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused import

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

import unittest, time, re
Copy link
Contributor

@freskoulix freskoulix Jun 23, 2016

Choose a reason for hiding this comment

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

unittest and re are unused imports

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


class TestSketchesCounters(SeleniumTestCase):

def test_sketches_counters(self):
self.driver = webdriver.Firefox()
Copy link
Contributor

Choose a reason for hiding this comment

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

Your class is a subclass of SeleniumTestCase which means that you already have an instance of webdriver in self.driver. No need to initialize the webdriver once more.

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

self.driver.implicitly_wait(30)
self.base_url = "https://staging.codebender.cc/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests should be agnostic of the target site that will run against.
This way the test will run against staging only.

You could use the self.open('/') method of your parent class:
https://github.com/codebendercc/seleniumTests/blob/master/codebender_testing/utils.py#L308
in order to avoid specifying the base url.

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

self.verificationErrors = []
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable seems unused inside the class, so why initialize it?

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

self.accept_next_alert = True
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, unused variable.

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
driver.get(self.base_url + "/")
Copy link
Contributor

@freskoulix freskoulix Jun 23, 2016

Choose a reason for hiding this comment

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

This could have been done with: self.open('/')

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("login_btn").click()
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("demo_user")
Copy link
Contributor

Choose a reason for hiding this comment

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

We have the credentials of the user at environment variables.
Check here how they are used: https://github.com/codebendercc/seleniumTests/blob/master/tests/common/home/test_home.py#L15

We must not hard-code user credentials or API keys.

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("password").clear()
Copy link
Contributor

Choose a reason for hiding this comment

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

You are mixing tabs with spaces in your file. Please use spaces only.

driver.find_element_by_id("password").send_keys("testerPASS")
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 password.

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("_submit").click()
driver.find_element_by_id("create_sketch_btn").click()


driver.find_element_by_id("create-sketch-modal-action-button").click()
time.sleep(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you use sleep()? You could have used expected conditions in order to wait for the elements you want.
Also you could have used the: self.get_element() method which internally uses an expected condition.
See here: https://github.com/codebendercc/seleniumTests/blob/master/codebender_testing/utils.py#L363

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("logo_small").click()
driver.find_element_by_id("create_sketch_btn").click()
driver.find_element_by_id("create-sketch-modal-action-button").click()
time.sleep(5)
driver.find_element_by_id("logo_small").click()
driver.find_element_by_id("create_sketch_btn").click()
driver.find_element_by_xpath("(//input[@name='create-sketch-modal-title'])[2]").click()
driver.find_element_by_id("create-sketch-modal-action-button").click()
time.sleep(5)
driver.find_element_by_id("logo_small").click()
driver.find_element_by_id("create_sketch_btn").click()
driver.find_element_by_xpath("(//input[@name='create-sketch-modal-title'])[2]").click()
driver.find_element_by_id("create-sketch-modal-action-button").click()
time.sleep(5)
driver.find_element_by_id("logo_small").click()
assert driver.find_element_by_id("private-sketches-counter").text=="2"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to read first the values of the current private/public sketches counters and assert against them.
You should not assume that the private/public sketches will be constant all the time.

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=="2"
assert driver.find_element_by_id("privateProjectAvailableNumber").text=="0"
assert driver.find_element_by_id("available-private-projects-counter").text=="0/2"
assert "Add more"==driver.find_element_by_link_text("Add more").text
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed spaces between the equability 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


#Private-->Public
driver.find_element_by_link_text("Edit Info").click()
time.sleep(5)
driver.find_element_by_name("edit-sketch-modal-title").click()
driver.find_element_by_id("edit-sketch-modal-action-button").click()
time.sleep(5)
assert driver.find_element_by_id("private-sketches-counter").text=="1"
assert driver.find_element_by_id("public-sketches-counter").text=="3"

#Public-->Private
driver.find_element_by_link_text("Edit Info").click()
time.sleep(5)
driver.find_element_by_xpath("(//input[@name='edit-sketch-modal-title'])[2]").click()
driver.find_element_by_id("edit-sketch-modal-action-button").click()
time.sleep(5)
assert driver.find_element_by_id("private-sketches-counter").text=="2"
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.

assert driver.find_element_by_id("public-sketches-counter").text=="2"
#for x in range(0, 3):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not leave commented code in your commits.

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_css_selector("i.fa.fa-trash").click()
# driver.find_element_by_css_selector("div.modal-footer.delete-sketch-modal-footer > button.btn.delete-sketch-modal-button").click()
#driver.find_element_by_css_selector("div.modal-footer.delete-sketch-modal-footer > button.btn.btn-danger").click()



driver.find_element_by_id("logout").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 should have used the: self.logout() function.
Check its implementation here: https://github.com/codebendercc/seleniumTests/blob/master/codebender_testing/utils.py#L353

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





Copy link
Contributor

@freskoulix freskoulix Jun 23, 2016

Choose a reason for hiding this comment

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

Multiple new lines on the end of file.
One new line on the end would be sufficient.

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