22from selenium .webdriver .chrome .service import Service as ChromeService
33from selenium .webdriver import Chrome
44from selenium .webdriver .common .keys import Keys
5+ from selenium .webdriver .common .by import By
56from selenium .common .exceptions import (
67 NoSuchDriverException , NoSuchElementException
78)
@@ -27,17 +28,17 @@ def setup_class(self):
2728 service = ChromeService (executable_path = "/usr/bin/chromedriver" )
2829 self .browser = Chrome (service = service )
2930 self .browser .get ('http://localhost:5000/' )
30- token = self .browser .find_element_by_name ( "token" )
31+ token = self .browser .find_element ( By . NAME , "token" )
3132 password = "foo"
3233 # Log in
3334 token .send_keys (password )
3435 token .send_keys (Keys .ENTER )
3536 time .sleep (.1 )
3637 try :
37- self .browser .find_element_by_xpath ( "//input[@value='Logout']" )
38+ self .browser .find_element ( By . XPATH , "//input[@value='Logout']" )
3839 except NoSuchElementException :
3940 raise ValueError ("Can't log in! Create a user 'foo' with the permissions "
40- "'read' and ' create' in your PERMISSIONS in the config" )
41+ "'read, create,delete ' in your PERMISSIONS in the config. " )
4142
4243 def teardown_class (self ):
4344 """
@@ -47,12 +48,12 @@ def teardown_class(self):
4748
4849 @property
4950 def page_body_lowercase (self ):
50- return self .browser .find_element_by_tag_name ( "body" ).text .lower ()
51+ return self .browser .find_element ( By . TAG_NAME , "body" ).text .lower ()
5152
5253 def test_unit_input_exists (self ):
53- unit_input = self .browser .find_element_by_name ( "maxlife-unit" )
54+ unit_input = self .browser .find_element ( By . NAME , "maxlife-unit" )
5455 assert unit_input is not None
55- value_input = self .browser .find_element_by_name ( "maxlife-value" )
56+ value_input = self .browser .find_element ( By . NAME , "maxlife-value" )
5657 assert value_input is not None
5758
5859 def fill_form (self ):
@@ -62,33 +63,33 @@ def fill_form(self):
6263 """
6364 filename = "test.txt"
6465 text_to_paste = "This is a test"
65- paste_input = self .browser .find_element_by_id ( "formupload" )
66+ paste_input = self .browser .find_element ( By . ID , "formupload" )
6667 paste_input .send_keys (text_to_paste )
67- filename_input = self .browser .find_element_by_id ( "filename" )
68+ filename_input = self .browser .find_element ( By . ID , "filename" )
6869 filename_input .send_keys (filename )
69- contenttype_input = self .browser .find_element_by_id ( "contenttype" )
70+ contenttype_input = self .browser .find_element ( By . ID , "contenttype" )
7071 contenttype_input .send_keys ("text/plain" )
7172 contenttype_input .send_keys (Keys .ENTER )
7273 time .sleep (.2 ) # give some time to render the next view
7374 return filename , text_to_paste
7475
7576 def delete_current_file (self ):
76- self .browser .find_element_by_id ( "del-btn" ).click ()
77+ self .browser .find_element ( By . ID , "del-btn" ).click ()
7778 time .sleep (.2 )
78- self .browser .find_element_by_class_name ( "bootbox-accept" ).click ()
79+ self .browser .find_element ( By . CLASS_NAME , "bootbox-accept" ).click ()
7980
8081 def test_paste_keep_forever (self ):
81- self .browser .find_element_by_xpath ( "//select[@name='maxlife-unit']/option[@value='forever']" ).click ()
82- value_input = self .browser .find_element_by_name ( "maxlife-value" )
82+ self .browser .find_element ( By . XPATH , "//select[@name='maxlife-unit']/option[@value='forever']" ).click ()
83+ value_input = self .browser .find_element ( By . NAME , "maxlife-value" )
8384 value_input .clear ()
8485 value_input .send_keys (1 )
8586 self .fill_form ()
8687 assert "max lifetime: forever" in self .page_body_lowercase
8788 self .delete_current_file ()
8889
8990 def test_paste_keep_minutes (self ):
90- self .browser .find_element_by_xpath ( "//select[@name='maxlife-unit']/option[@value='minutes']" ).click ()
91- value_input = self .browser .find_element_by_name ( "maxlife-value" )
91+ self .browser .find_element ( By . XPATH , "//select[@name='maxlife-unit']/option[@value='minutes']" ).click ()
92+ value_input = self .browser .find_element ( By . NAME , "maxlife-value" )
9293 value_input .clear ()
9394 value_input .send_keys (1 )
9495 self .fill_form ()
@@ -102,18 +103,18 @@ def test_filename_gets_displayed(self):
102103
103104 def test_pasted_text_gets_displayed (self ):
104105 _ , pasted_text = self .fill_form ()
105- self .browser .find_element_by_id ( "inline-btn" ).click ()
106+ self .browser .find_element ( By . ID , "inline-btn" ).click ()
106107 assert pasted_text .lower () in self .page_body_lowercase
107108 self .browser .back ()
108109 self .delete_current_file ()
109110
110111 @pytest .mark .slow
111112 def test_file_gets_deleted_after_expiry_time (self ):
112- self .browser .find_element_by_xpath ( "//select[@name='maxlife-unit']/option[@value='minutes']" ).click ()
113- value_input = self .browser .find_element_by_name ( "maxlife-value" )
113+ self .browser .find_element ( By . XPATH , "//select[@name='maxlife-unit']/option[@value='minutes']" ).click ()
114+ value_input = self .browser .find_element ( By . NAME , "maxlife-value" )
114115 value_input .clear ()
115116 value_input .send_keys (1 )
116117 self .fill_form ()
117118 time .sleep (61 )
118- self .browser .find_element_by_id ( "inline-btn" ).click ()
119+ self .browser .find_element ( By . ID , "inline-btn" ).click ()
119120 assert "not found" in self .page_body_lowercase
0 commit comments