Skip to content

Commit 005e761

Browse files
committed
Merge pull request #17 from codebendercc/various_fixes
Various fixes
2 parents e0bb780 + f5b7f11 commit 005e761

29 files changed

+460
-66
lines changed

bin/env_vars.sh.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
export CAPABILITIES='capabilities_firefox.yaml'
4+
35
SAUCELABS_USER=""
46
SAUCELABS_KEY=""
57
export CODEBENDER_SELENIUM_HUB_URL=http://${SAUCELABS_USER}:${SAUCELABS_KEY}@ondemand.saucelabs.com:80/wd/hub
@@ -13,3 +15,7 @@ export DISQUS_API_PUBLIC=""
1315
export DISQUS_SSO_ID=""
1416
export DISQUS_SSO_USERNAME=""
1517
export DISQUS_SSO_EMAIL=""
18+
19+
export EMAIL=""
20+
21+
export ROOTDIR="/path/to/seleniumTests"

bin/seleniumbender

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/bin/bash
22

3-
export CAPABILITIES='capabilities_firefox.yaml'
4-
53
source ./env_vars.sh
64

7-
ROOTDIR="/path/to/seleniumTests"
8-
95
if [ $# -lt 1 ]; then
106
echo "Please provide an argument or run -h(--help) option"
117
exit 1
128
fi
139

1410
app_name="$0"
15-
common=0
16-
libraries=0
11+
12+
target=0
1713
examples=0
14+
libraries=0
1815
sketches=0
16+
common=0
17+
noplugin=0
18+
walkthrough=0
19+
staging=0
1920

2021
while true; do
2122
case "$1" in
@@ -25,17 +26,32 @@ while true; do
2526
" libraries - Visits all the libraries and examples at libraries view\n" \
2627
" examples - Compiles all the examples at libraries view\n" \
2728
" sketches - Compiles the examples of user cb_compile_tester\n" \
29+
" target - Compiles the examples of given libraries as a comma separated list\n" \
30+
" noplugin - Runs tests that do not need plugin installed\n" \
31+
" walkthrough - Runs tests for walkthrough\n" \
32+
" staging - Runs tests in staging\n" \
2833
" help - Display this help and exit"
2934
exit 0
3035
;;
31-
common) common=1
32-
;;
33-
libraries) libraries=1
36+
target) target=1
37+
shift
38+
TARGETS=$@
39+
break
3440
;;
3541
examples) examples=1
3642
;;
43+
libraries) libraries=1
44+
;;
3745
sketches) sketches=1
3846
;;
47+
common) common=1
48+
;;
49+
noplugin) noplugin=1
50+
;;
51+
walkthrough) walkthrough=1
52+
;;
53+
staging) staging=1
54+
;;
3955
-*) echo -e "error: unknown argument: ${1}.\nRun ${app_name} -h."
4056
exit 1
4157
;;
@@ -52,25 +68,72 @@ SOURCE="codebender_cc"
5268

5369
email_date=$(date +"%Y-%m-%d %H:%M:%S")
5470

55-
if [ "${common}" -eq 1 ]; then
56-
IDENTIFIER="common"
57-
tox tests/common -- --url=${URL} --source=${SOURCE}
58-
RETVAL=$?
59-
if [ "${RETVAL}" -eq 1 ]; then
60-
mail -s "Selenium Tests: ${IDENTIFIER} Failed To Run" [email protected] <<< 'Something went wrong with common tests. Please check the logs.'
61-
exit ${RETVAL}
62-
fi
71+
RETVAL=0
72+
NO_LOGS=0 # flag for tests that do not send any logs on their email
73+
74+
if [ "${target}" -eq 1 ]; then
75+
IDENTIFIER="test_target_libraries"
76+
tox tests/target_libraries -- --url=${URL} --source=${SOURCE} -F --plugin --libraries=${TARGETS}
6377
elif [ "${examples}" -eq 1 ]; then
6478
IDENTIFIER="libraries_test"
65-
tox tests/libraries -- --url=${URL} --source=${SOURCE} -F
79+
tox tests/libraries -- --url=${URL} --source=${SOURCE} -F --plugin
6680
elif [ "${libraries}" -eq 1 ]; then
6781
IDENTIFIER="libraries_fetch"
68-
tox tests/libraries_fetch -- --url=${URL} --source=${SOURCE} -F
82+
tox tests/libraries_fetch -- --url=${URL} --source=${SOURCE} -F --plugin
6983
elif [ "${sketches}" -eq 1 ]; then
7084
IDENTIFIER="cb_compile_tester"
71-
tox tests/compile_tester -- --url=${URL} --source=${SOURCE} -F
85+
tox tests/compile_tester -- --url=${URL} --source=${SOURCE} -F --plugin
86+
elif [ "${common}" -eq 1 ]; then
87+
IDENTIFIER="common"
88+
tox tests/common -- --url=${URL} --source=${SOURCE} --plugin
89+
RETVAL=$?
90+
NO_LOGS=1
91+
elif [ "${noplugin}" -eq 1 ]; then
92+
IDENTIFIER="noplugin"
93+
tox tests/noplugin -- --url=${URL} --source=${SOURCE}
94+
RETVAL=$?
95+
NO_LOGS=1
96+
elif [ "${walkthrough}" -eq 1 ]; then
97+
IDENTIFIER="walkthrough"
98+
RETVALS=()
99+
# Linux
100+
export SELENIUM_USER_AGENT='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
101+
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
102+
RETVALS+=($?)
103+
# Windows
104+
export SELENIUM_USER_AGENT='Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
105+
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
106+
RETVALS+=($?)
107+
# MacOSX
108+
export SELENIUM_USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
109+
tox tests/walkthrough -- --url=${URL} --source=${SOURCE} --plugin
110+
RETVALS+=($?)
111+
112+
for i in "${RETVALS[@]}"
113+
do
114+
if [ ${i} -ne 0 ]; then
115+
RETVAL=${i}
116+
fi
117+
done
118+
NO_LOGS=1
119+
elif [ "${staging}" -eq 1 ]; then
120+
IDENTIFIER="cb_compile_tester_staging"
121+
URL="https://staging.codebender.cc"
122+
tox tests/compile_tester -- --url=${URL} --source=${SOURCE} -F --plugin
123+
# No need to send email for tests in staging
124+
exit $?
125+
fi
126+
127+
# email notification without attaching any logs
128+
if [ ${RETVAL} -ne 0 ]; then
129+
mail -s "Selenium Tests: ${IDENTIFIER} Failed To Run" ${EMAIL} <<< "Something went wrong with ${IDENTIFIER} tests. Please check the logs."
130+
fi
131+
132+
if [ ${NO_LOGS} -eq 1 ]; then
133+
exit ${RETVAL}
72134
fi
73135

136+
# email notification with attaching the produced reports
74137
DATE=$(date +"%Y-%m-%d") # Get the current date
75138
LOGS="${ROOTDIR}/logs"
76139
REPORTS="${ROOTDIR}/reports"
@@ -80,5 +143,5 @@ reportfile=$(ls -t ${REPORTS} | egrep "${DATE}.*${IDENTIFIER}" | head -1)
80143
diffnum=$(ls -t ${REPORTS} | egrep "${DATE}.*${IDENTIFIER}" | head -1 | cut -d'_' -f6)
81144
changes=${diffnum:0:1}
82145

83-
(echo "Changes since the last time: ${changes}"; uuencode "${LOGS}/${LOGFILE}" "${LOGFILE}"; uuencode "${REPORTS}/${REPORTFILE}" "${REPORTFILE}") \
84-
| mail -s "Selenium Tests Report: ${IDENTIFIER} ${email_date} Changes: ${changes}" [email protected]
146+
(echo "Changes since the last time: ${changes}"; uuencode "${LOGS}/${logfile}" "${logfile}"; uuencode "${REPORTS}/${reportfile}" "${reportfile}") \
147+
| mail -s "Selenium Tests Report: ${IDENTIFIER} ${email_date} Changes: ${changes}" ${EMAIL}

codebender_testing/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
66
import yaml
77
import simplejson
8+
import pytest
89

910

1011
def _rel_path(*args):
@@ -24,6 +25,7 @@ def jsondump(data):
2425
BASE_URL = "http://localhost"
2526
# URL of the actual Codebender website
2627
LIVE_SITE_URL = "https://codebender.cc"
28+
STAGING_SITE_URL = "https://staging.codebender.cc"
2729

2830
# Names of sources (i.e. repositories) used to generate the codebender site.
2931
SOURCE_BACHELOR = 'bachelor'
@@ -32,6 +34,7 @@ def jsondump(data):
3234
# User whose projects we'd like to compile in our compile_tester
3335
# test case(s).
3436
COMPILE_TESTER_URL = "/user/cb_compile_tester"
37+
COMPILE_TESTER_STAGING_URL = "/user/demo_user"
3538

3639
# The prefix for all filenames of log files.
3740
# Note that it is given as a time format string, which will
@@ -40,6 +43,7 @@ def jsondump(data):
4043

4144
# Logfile for COMPILE_TESTER compilation results
4245
COMPILE_TESTER_LOGFILE = LOGFILE_PREFIX.format(log_name="cb_compile_tester")
46+
COMPILE_TESTER_LOGFILE_STAGING = LOGFILE_PREFIX.format(log_name="staging_cb_compile_tester")
4347

4448
# Logfile for /libraries compilation results
4549
LIBRARIES_TEST_LOGFILE = LOGFILE_PREFIX.format(log_name="libraries_test")
@@ -79,7 +83,8 @@ def jsondump(data):
7983
'LOCATE_ELEMENT': 30
8084
}
8185

82-
TESTS_USER_AGENT = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
86+
DEFAULT_USER_AGENT = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0 codebender-selenium'
87+
TESTS_USER_AGENT = os.getenv('SELENIUM_USER_AGENT', DEFAULT_USER_AGENT)
8388

8489
# Set up Selenium Webdrivers to be used for selenium tests
8590
def _get_firefox_profile():
@@ -88,9 +93,10 @@ def _get_firefox_profile():
8893
extension.
8994
"""
9095
firefox_profile = webdriver.FirefoxProfile()
91-
firefox_profile.add_extension(
92-
extension=os.path.join(_EXTENSIONS_DIR, _FIREFOX_EXTENSION_FNAME)
93-
)
96+
if pytest.config.getoption("--plugin"):
97+
firefox_profile.add_extension(
98+
extension=os.path.join(_EXTENSIONS_DIR, _FIREFOX_EXTENSION_FNAME)
99+
)
94100
return firefox_profile
95101

96102
def get_browsers(capabilities_file_path=None):

codebender_testing/disqus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
7777
def handle_library_comment(self, library, current_date, log):
7878
url = '/library/' + library
7979
identifier = 'ident:' + url
80+
if url not in log:
81+
log[url] = {}
8082
try:
8183
paginator = disqusapi.Paginator(self.disqus.api.threads.list, forum=FORUM, thread=identifier, method='GET')
8284
if paginator:
8385
for page in paginator:
8486
post_id, existing_message = self.get_posts(page['id'])
8587
if post_id and existing_message:
8688
new_message = self.messages['library'].replace('TEST_DATE', current_date)
87-
if url not in log:
88-
log[url] = {}
8989
log[url]['comment'] = self.update_post(post_id, new_message)
9090
else:
9191
log[url]['comment'] = False

codebender_testing/utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def _move_file_to_dropzone_script(dropzone_selector):
7575
VERIFICATION_SUCCESSFUL_MESSAGE = "Verification Successful"
7676
VERIFICATION_FAILED_MESSAGE = "Verification failed."
7777

78+
VERIFICATION_SUCCESSFUL_MESSAGE_EDITOR = 'Verification successful!'
79+
VERIFICATION_FAILED_MESSAGE_EDITOR = 'Verification failed!'
80+
7881
# Max test runtime into saucelabs
7982
# 2.5 hours (3 hours max)
8083
SAUCELABS_TIMEOUT_SECONDS = 10800 - 1800
@@ -344,7 +347,7 @@ def get_elements(self, *locator):
344347
"""Like `get_element`, but returns a list of all elements matching
345348
the selector."""
346349
WebDriverWait(self.driver, TIMEOUT['LOCATE_ELEMENT']).until(
347-
expected_conditions.visibility_of_all_elements_located_by(locator))
350+
expected_conditions.presence_of_all_elements_located(locator))
348351
return self.driver.find_elements(*locator)
349352

350353
def find(self, selector):
@@ -460,7 +463,7 @@ def open_all_libraries_and_examples(self, url, logfile):
460463

461464
report_creator('fetch', log_entry, log_file)
462465

463-
def compile_sketch(self, url, boards, iframe=False):
466+
def compile_sketch(self, url, boards, iframe=False, project_view=False):
464467
"""Compiles the sketch located at `url`, or an iframe within the page
465468
referred to by `url`. Raises an exception if it does not compile.
466469
"""
@@ -481,6 +484,11 @@ def compile_sketch(self, url, boards, iframe=False):
481484
result = {
482485
'board': board
483486
}
487+
verification_success_message = VERIFICATION_SUCCESSFUL_MESSAGE_EDITOR
488+
verification_failed_message = VERIFICATION_FAILED_MESSAGE_EDITOR
489+
if project_view or iframe:
490+
verification_success_message = VERIFICATION_SUCCESSFUL_MESSAGE
491+
verification_failed_message = VERIFICATION_FAILED_MESSAGE
484492
try:
485493
self.execute_script(SELECT_BOARD_SCRIPT(board), '$', 'compilerflasher.pluginHandler.plugin_found')
486494
self.execute_script(_VERIFY_SCRIPT, 'compilerflasher')
@@ -490,15 +498,14 @@ def compile_sketch(self, url, boards, iframe=False):
490498
compile_result = WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
491499
any_text_to_be_present_in_element(
492500
(By.CSS_SELECTOR, "[id$=operation_output]"),
493-
VERIFICATION_SUCCESSFUL_MESSAGE, VERIFICATION_FAILED_MESSAGE
501+
verification_success_message, verification_failed_message
494502
)
495503
)
496504
except WebDriverException as error:
497505
compile_result = "%s; %s" % (type(error).__name__, str(error))
498506
result['status'] = 'error'
499507
result['message'] = compile_result
500-
501-
if compile_result == VERIFICATION_SUCCESSFUL_MESSAGE:
508+
if compile_result == verification_success_message:
502509
result['status'] = 'success'
503510
else:
504511
result['status'] = 'fail'
@@ -521,7 +528,7 @@ def compile_all_sketches(self, url, selector, **kwargs):
521528
assert len(sketches) > 0
522529
self.compile_sketches(sketches, **kwargs)
523530

524-
def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='sketch', create_report=False, comment=False):
531+
def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=None, compile_type='sketch', create_report=False, comment=False):
525532
"""Compiles the sketches with URLs given by the `sketches` list.
526533
`logfile` specifies a path to a file to which test results will be
527534
logged. If it is not `None`, compile errors will not cause the test
@@ -577,7 +584,7 @@ def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='s
577584

578585
if len(boards) > 0:
579586
# Run Verify
580-
results = self.compile_sketch(sketch, boards, iframe=iframe)
587+
results = self.compile_sketch(sketch, boards, iframe=iframe, project_view=project_view)
581588
else:
582589
results = [
583590
{
@@ -587,6 +594,7 @@ def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='s
587594

588595
# Used when not funning in Full mode
589596
if logfile is None or not self.run_full_compile_tests:
597+
toc = time.time()
590598
continue
591599

592600
# Register current URL into log
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)