1212
1313pjoin = os .path .join
1414
15+
1516def _wait_for_server (proc , info_file_path ):
1617 """Wait 30 seconds for the notebook server to start"""
1718 for i in range (300 ):
@@ -28,6 +29,7 @@ def _wait_for_server(proc, info_file_path):
2829 time .sleep (0.1 )
2930 raise RuntimeError ("Didn't find %s in 30 seconds" , info_file_path )
3031
32+
3133@pytest .fixture (scope = 'session' )
3234def notebook_server ():
3335 info = {}
@@ -50,10 +52,11 @@ def notebook_server():
5052 # run with a base URL that would be escaped,
5153 # to test that we don't double-escape URLs
5254 '--NotebookApp.base_url=/a@b/' ,
53- ]
55+ ]
5456 print ("command=" , command )
5557 proc = info ['popen' ] = Popen (command , cwd = nbdir , env = env )
56- info_file_path = pjoin (td , 'jupyter_runtime' , 'nbserver-%i.json' % proc .pid )
58+ info_file_path = pjoin (td , 'jupyter_runtime' ,
59+ 'nbserver-%i.json' % proc .pid )
5760 info .update (_wait_for_server (proc , info_file_path ))
5861
5962 print ("Notebook server info:" , info )
@@ -63,26 +66,38 @@ def notebook_server():
6366 requests .post (urljoin (info ['url' ], 'api/shutdown' ),
6467 headers = {'Authorization' : 'token ' + info ['token' ]})
6568
69+
70+ def make_sauce_driver ():
71+ """This function helps travis create a driver on Sauce Labs.
72+
73+ This function will err if used without specifying the variables expected
74+ in that context.
75+ """
76+
77+ username = os .environ ["SAUCE_USERNAME" ]
78+ access_key = os .environ ["SAUCE_ACCESS_KEY" ]
79+ capabilities = {
80+ "tunnel-identifier" : os .environ ["TRAVIS_JOB_NUMBER" ],
81+ "build" : os .environ ["TRAVIS_BUILD_NUMBER" ],
82+ "tags" : [os .environ ['TRAVIS_PYTHON_VERSION' ], 'CI' ],
83+ "platform" : "Windows 10" ,
84+ "browserName" : os .environ ['JUPYTER_TEST_BROWSER' ],
85+ "version" : "latest" ,
86+ }
87+ if capabilities ['browserName' ] == 'firefox' :
88+ # Attempt to work around issue where browser loses authentication
89+ capabilities ['version' ] = '57.0'
90+ hub_url = "%s:%s@localhost:4445" % (username , access_key )
91+ print ("Connecting remote driver on Sauce Labs" )
92+ driver = Remote (desired_capabilities = capabilities ,
93+ command_executor = "http://%s/wd/hub" % hub_url )
94+ return driver
95+
96+
6697@pytest .fixture (scope = 'session' )
6798def selenium_driver ():
6899 if os .environ .get ('SAUCE_USERNAME' ):
69- username = os .environ ["SAUCE_USERNAME" ]
70- access_key = os .environ ["SAUCE_ACCESS_KEY" ]
71- capabilities = {
72- "tunnel-identifier" : os .environ ["TRAVIS_JOB_NUMBER" ],
73- "build" : os .environ ["TRAVIS_BUILD_NUMBER" ],
74- "tags" : [os .environ ['TRAVIS_PYTHON_VERSION' ], 'CI' ],
75- "platform" : "Windows 10" ,
76- "browserName" : os .environ ['JUPYTER_TEST_BROWSER' ],
77- "version" : "latest" ,
78- }
79- if capabilities ['browserName' ] == 'firefox' :
80- # Attempt to work around issue where browser loses authentication
81- capabilities ['version' ] = '57.0'
82- hub_url = "%s:%s@localhost:4445" % (username , access_key )
83- print ("Connecting remote driver on Sauce Labs" )
84- driver = Remote (desired_capabilities = capabilities ,
85- command_executor = "http://%s/wd/hub" % hub_url )
100+ driver = make_sauce_driver ()
86101 elif os .environ .get ('JUPYTER_TEST_BROWSER' ) == 'chrome' :
87102 driver = Chrome ()
88103 else :
@@ -93,7 +108,8 @@ def selenium_driver():
93108 # Teardown
94109 driver .quit ()
95110
96- @pytest .fixture
111+
112+ @pytest .fixture (scope = 'module' )
97113def authenticated_browser (selenium_driver , notebook_server ):
98114 selenium_driver .jupyter_server_info = notebook_server
99115 selenium_driver .get ("{url}?token={token}" .format (** notebook_server ))
0 commit comments