33"""Carry out functional tests on OneZoom pages using an automated browser via selenium
44
55 Example: carry out all tests
6- nosetests -w ./ tests/functional
6+ python -m pytest ./ tests/functional
77 Example: carry out all tests for unsponsorable sites (museum displays)
8- nosetests -vs functional/sponsorship/test_unsponsorable_site.py
8+ python -m pytest -s functional/sponsorship/test_unsponsorable_site.py
99 Example: carry out test that unsponsorable sites give the correct page for invalid otts
10- nosetests -vs functional/sponsorship/test_unsponsorable_site.py:TestUnsponsorableSite.test_invalid
11-
12- If you have installed the 'rednose' package (pip3 install rednose), you can get nicer output by e.g.
13-
14- nosetests -vs ./tests/functional --rednose
10+ python -m pytest -s functional/sponsorship/test_unsponsorable_site.py:TestUnsponsorableSite.test_invalid
1511
1612 To carry out tests on a remote machine, you can specify a [url][server] and [url][port]
1713 in a config file, which will not give the FunctionalTest class an is_local attribute
1814 and hence will skip tests marked @attr('is_local'). E.g. for testing beta.onezoom.org, you can do
19-
15+ TODO: this is not yet implemented for the functional tests
16+ in nosetests we used to do...
2017 nosetests -vs ./tests/functional --rednose --tc-file beta_cfg.ini
21-
18+
2219"""
2320
2421import sys
2522import json
2623import os
2724import re
2825from datetime import datetime
29- from nose import tools
3026import requests
3127import subprocess
3228import logging
@@ -52,7 +48,7 @@ class FunctionalTest(object):
5248 is_local = Web2py_server .is_local ()
5349
5450 @classmethod
55- def setUpClass (self ):
51+ def setup_class (self ):
5652 def striptext_in_file (line , file ):
5753 """
5854 look for the line as a starting line in the file, stripping whitespace
@@ -97,55 +93,50 @@ def striptext_in_file(line, file):
9793 selenium_logger .setLevel (logging .WARNING )
9894 #chrome_options = webdriver.ChromeOptions()
9995 #chrome_options.add_experimental_option("mobileEmulation", { "deviceName": "iPhone 7" })
100- self . caps = webdriver .ChromeOptions (). to_capabilities ()
96+ chrome_options = webdriver .ChromeOptions ()
10197 # enable browser logging
102- self . caps [ ' loggingPrefs'] = { 'browser' :'ALL' }
103- self .browser = webdriver .Chrome (desired_capabilities = self . caps )
98+ chrome_options . set_capability ( 'goog: loggingPrefs', { 'browser' :'ALL' })
99+ self .browser = webdriver .Chrome (options = chrome_options )
104100 self .browser .implicitly_wait (1 )
105101
106102 @classmethod
107- def tearDownClass (self ):
103+ def teardown_class (self ):
108104 #should test here that we don't have any console.log errors (although we might have logs).
109105 self .browser .quit ()
110106 self .web2py .stop_server ()
111107
112- def setup (self ):
108+ def setup_method (self ):
113109 """
114110 By default, clear logs before each test
115111 """
116112 self .clear_log ()
117113
118- def teardown (self ):
114+ def teardown_method (self ):
119115 """
120116 By default, check javascript errors after each test. If you don't want to do this, e.g. for iframes, thic can be overridden
121117 """
122118 self .clear_log (check_errors = True )
123119
124- @tools .nottest
125120 def element_by_tag_name_exists (self , tag_name ):
126- try : self .browser .find_element_by_tag_name ( tag_name )
121+ try : self .browser .find_element ( By . TAG_NAME , tag_name )
127122 except NoSuchElementException : return False
128123 return True
129124
130- @tools .nottest
131125 def element_by_id_exists (self , id ):
132- try : self .browser .find_element_by_id ( id )
126+ try : self .browser .find_element ( By . ID , id )
133127 except NoSuchElementException : return False
134128 return True
135129
136- @tools .nottest
137130 def element_by_class_exists (self , cls ):
138- try : self .browser .find_element_by_class_name ( cls )
131+ try : self .browser .find_element ( By . CLASS_NAME , cls )
139132 except NoSuchElementException : return False
140133 return True
141134
142- @tools .nottest
143135 def element_by_css_selector_exists (self , css ):
144- try : self .browser .find_element_by_css_selector ( css )
136+ try : self .browser .find_element ( By . CSS_SELECTOR , css )
145137 except NoSuchElementException : return False
146138 return True
147139
148- @tools .nottest
149140 def clear_log (self , check_errors = False ):
150141 log = self .browser .get_log ('browser' )
151142 if check_errors :
@@ -155,7 +146,6 @@ def clear_log(self, check_errors=False):
155146 if not (message ['message' ].startswith ("https://media.eol.org/content" ) and "404 (Not Found)" in message ['message' ]):
156147 assert False , "Javascript issue of level {}, : {}" .format (message ['level' ], message ['message' ])
157148
158- @tools .nottest
159149 def zoom_disabled (self ):
160150 """
161151 Check that the touch zoom functionality is disabled.
@@ -209,17 +199,17 @@ def has_linkouts(browser, include_site_internal):
209199 Depending on the param passed in, we may want to allow internal (relative) links such as
210200 <a href='/sponsored'></a>
211201 """
212- for tag in browser .find_elements_by_css_selector ( "[href^='http']" ):
202+ for tag in browser .find_elements ( By . CSS_SELECTOR , "[href^='http']" ):
213203 if tag .tag_name != u'link' and not tag .get_attribute ('href' ).startswith ('http://127.0.0.1' ): #should allow e.g. <link href="styles.css"> and http://127.0.0.1:..
214204 return True
215- for tag in browser .find_elements_by_css_selector ( "[href^='//']" ):
205+ for tag in browser .find_elements ( By . CSS_SELECTOR , "[href^='//']" ):
216206 if tag .tag_name != u'link' : #should allow e.g. <link href="styles.css">
217207 return True
218208
219209 #all hrefs should now be http or https refs to local stuff. We should double check this
220210 #by looking at the tag.attribute which is fully expanded by selenium/chrome to include http
221211 #but we should exclude all page-local links (i.e. beginning with #)
222- for tag in browser .find_elements_by_css_selector ( '[href]:not([href^="#"])' ):
212+ for tag in browser .find_elements ( By . CSS_SELECTOR , '[href]:not([href^="#"])' ):
223213 if tag .tag_name != u'link' :
224214 if include_site_internal :
225215 return True
@@ -234,13 +224,13 @@ def has_linkouts(browser, include_site_internal):
234224def web2py_date_accessed (browser ):
235225 #assumes that we have injected the access date into a meta element called 'date_accessed'
236226 #using the web2py code {{response.meta.date_accessed = request.now}}
237- return datetime .strptime (browser .find_element_by_xpath ( "//meta[@name='date_accessed']" ).get_attribute ("content" ), date_format )
227+ return datetime .strptime (browser .find_element ( By . XPATH , "//meta[@name='date_accessed']" ).get_attribute ("content" ), date_format )
238228
239229def web2py_viewname_contains (browser , expected_view ):
240230 #Checks if we have injected the view name into a meta element called 'viewfile'
241231 #using the web2py code {{response.meta.viewfile = response.view}}
242232 try :
243- return expected_view in browser .find_element_by_xpath ( "//meta[@name='viewfile']" ).get_attribute ("content" )
233+ return expected_view in browser .find_element ( By . XPATH , "//meta[@name='viewfile']" ).get_attribute ("content" )
244234 except NoSuchElementException :
245235 return False
246236
0 commit comments