1+
2+ import time
3+ import unittest
4+ from selenium import webdriver
5+ from selenium .webdriver .common .by import By
6+ from selenium .webdriver .support .ui import WebDriverWait
7+ from selenium .webdriver .support import expected_conditions as EC
8+
9+ class TestSuperseder (unittest .TestCase ):
10+
11+ def setUp (self ):
12+ options = webdriver .FirefoxOptions ()
13+ options .add_argument ('--headless' )
14+
15+ self .driver = webdriver .Firefox (options = options )
16+
17+
18+ def tearDown (self ):
19+ self .driver .quit ()
20+
21+ def test_Untitled (self ):
22+ wait = WebDriverWait (self .driver , 10 )
23+
24+ # Step 1: Open URL /demo/
25+ self .driver .get ("http://localhost:8917/demo/" )
26+
27+ # Step 2: Set window size
28+ self .driver .set_window_size (786 , 824 )
29+
30+ # Step 3: Click on element with name '__login_name'
31+ wait .until (EC .element_to_be_clickable ((By .NAME , "__login_name" ))).click ()
32+
33+ # Step 4: Type 'admin' into element with name '__login_name'
34+ wait .until (EC .element_to_be_clickable ((By .NAME , "__login_name" ))).send_keys ("admin" )
35+
36+ # Step 5: Click on element with name '__login_password'
37+ wait .until (EC .element_to_be_clickable ((By .NAME , "__login_password" ))).click ()
38+
39+ # Step 6: Type 'admin' into element with name '__login_password'
40+ wait .until (EC .element_to_be_clickable ((By .NAME , "__login_password" ))).send_keys ("admin" )
41+
42+ # Step 7: Click on element with CSS selector '.userblock > input:nth-child(12)'
43+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , ".userblock > input:nth-child(12)" ))).click ()
44+
45+ # Step 8: Click on element with link text 'Create New'
46+ wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "Create New" ))).click ()
47+
48+ # Step 9: Click on element with link text '(list)'
49+ wait .until (EC .element_to_be_clickable ((By .LINK_TEXT , "(list)" ))).click ()
50+
51+ # Step 10: Store window handle
52+ main_window_handle = self .driver .current_window_handle
53+
54+ # Step 11: Switch to the popup window
55+ for handle in self .driver .window_handles :
56+ if handle != main_window_handle :
57+ self .driver .switch_to .window (handle )
58+
59+ # Step 12: Click on element with CSS selector 'tr:nth-child(3) > td:nth-child(2)'
60+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "tr:nth-child(3) > td:nth-child(2)" ))).click ()
61+
62+ # Step 13: Click on element with CSS selector 'tr:nth-child(5) > td:nth-child(2)'
63+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "tr:nth-child(5) > td:nth-child(2)" ))).click ()
64+ #
65+ # Step 14: Click on element with CSS selector 'button:nth-child(1)'
66+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "button:nth-child(1)" ))).click ()
67+ #
68+ # Step 15: Click on element with CSS selector 'tr:nth-child(4) > td:nth-child(2)'
69+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "tr:nth-child(4) > td:nth-child(2)" ))).click ()
70+ #
71+
72+
73+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "button:nth-child(1)" ))).click ()
74+ #
75+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "tr:nth-child(6) > td:nth-child(2)" ))).click ()
76+ #
77+
78+ # Step 16: Click on element with CSS selector 'button:nth-child(3)'
79+ wait .until (EC .element_to_be_clickable ((By .CSS_SELECTOR , "button:nth-child(3)" ))).click ()
80+ # time.sleep(2)
81+ # Step 17: Switch back to the main window
82+ self .driver .switch_to .window (main_window_handle )
83+
84+ # Step 18: Click on element with name 'superseder'AER4
85+ wait .until (EC .element_to_be_clickable ((By .NAME , "superseder" ))).click ()
86+ # time.sleep(2)
87+ # Step 19: Close the current window
88+ self .driver .close ()
89+ print ("Test Case 3 -- success" )
90+
91+
92+
93+ class TestNosy (unittest .TestCase ):
94+ def setUp (self ):
95+ # Initialize the Firefox driver with headless option setting to True.
96+ options = webdriver .FirefoxOptions ()
97+ options .add_argument ('--headless' )
98+
99+ self .driver = webdriver .Firefox (options = options )
100+
101+ def tearDown (self ):
102+ # Close the browser
103+ self .driver .quit ()
104+
105+ def test_demo (self ):
106+ # Open the URL
107+ self .driver .get ('http://localhost:8917/demo/' )
108+
109+ # Enter login credentials
110+ self .driver .find_element (By .NAME , '__login_name' ).send_keys ('admin' )
111+ self .driver .find_element (By .NAME , '__login_password' ).send_keys ('admin' )
112+
113+ # Submit the login form
114+ self .driver .find_element (By .CSS_SELECTOR , '.userblock > input:nth-child(12)' ).click ()
115+
116+ # Wait until the 'Create New' link is present and click on it
117+ WebDriverWait (self .driver , 10 ).until (
118+ EC .presence_of_element_located ((By .LINK_TEXT , 'Create New' ))
119+ )
120+ self .driver .find_element (By .LINK_TEXT , 'Create New' ).click ()
121+
122+ # Wait until the popup is loaded and click on the help link
123+ WebDriverWait (self .driver , 10 ).until (
124+ EC .presence_of_element_located ((By .CSS_SELECTOR , 'tr:nth-child(3) > td:nth-child(4) .classhelp' ))
125+ )
126+ #
127+ self .driver .find_element (By .CSS_SELECTOR , 'tr:nth-child(3) > td:nth-child(4) .classhelp' ).click ()
128+
129+ # Switch to the new window
130+ handles = self .driver .window_handles
131+ self .driver .switch_to .window (handles [- 1 ])
132+ # self.driver.maximize_window()
133+
134+
135+ # Wait until the new window is loaded
136+ WebDriverWait (self .driver , 10 ).until (
137+ EC .presence_of_element_located ((By .ID , 'username' ))
138+ )
139+
140+ # Type 'de' in the search box
141+ self .driver .find_element (By .ID , 'username' ).send_keys ('de' )
142+
143+ # Click on the search button
144+ self .driver .find_element (By .CSS_SELECTOR , 'button:nth-child(1)' ).click ()
145+
146+ # Wait until the results are loaded
147+ WebDriverWait (self .driver , 10 ).until (
148+ EC .presence_of_all_elements_located ((By .CSS_SELECTOR , 'tbody td:nth-child(2)' ))
149+ )
150+
151+ # Click on the first result
152+ self .driver .find_element (By .CSS_SELECTOR , 'tbody td:nth-child(2)' ).click ()
153+
154+ # Wait until the new page is loaded
155+ WebDriverWait (self .driver , 10 ).until (
156+ EC .presence_of_element_located ((By .CSS_SELECTOR , 'button:nth-child(3)' ))
157+ )
158+ # time.sleep(3)
159+
160+ search_button = self .driver .find_element (By .XPATH , "//button[contains(.,'Reset')]" )
161+ search_button .click ()
162+ #
163+
164+
165+ self .driver .find_element (By .ID , 'username' ).send_keys ('mi' )
166+
167+ # Click on the search button
168+ self .driver .find_element (By .CSS_SELECTOR , 'button:nth-child(1)' ).click ()
169+
170+ # Wait until the results are loaded
171+ WebDriverWait (self .driver , 10 ).until (
172+ EC .presence_of_all_elements_located ((By .CSS_SELECTOR , 'tbody td:nth-child(2)' ))
173+ )
174+
175+ # Click on the first result
176+ self .driver .find_element (By .CSS_SELECTOR , 'tbody td:nth-child(2)' ).click ()
177+
178+ # Wait until the new page is loaded
179+ WebDriverWait (self .driver , 10 ).until (
180+ EC .presence_of_element_located ((By .CSS_SELECTOR , 'button:nth-child(3)' ))
181+ )
182+
183+ search_button = self .driver .find_element (By .XPATH , "//button[contains(.,'Reset')]" )
184+ search_button .click ()
185+ #
186+
187+ search_button = self .driver .find_element (By .XPATH , "//button[contains(.,'Search')]" )
188+ search_button .click ()
189+ #
190+
191+ item_to_select = self .driver .find_element (By .XPATH , "//tbody/tr[3]/td[2]" )
192+ item_to_select .click ()
193+ #
194+ # Click on the 'Apply' button
195+ self .driver .find_element (By .CSS_SELECTOR , 'button:nth-child(3)' ).click ()
196+
197+ # Switch back to the original window
198+ self .driver .switch_to .window (handles [0 ])
199+ #
200+ # Wait until the new page is loaded
201+ WebDriverWait (self .driver , 10 ).until (
202+ EC .presence_of_element_located ((By .NAME , 'nosy' ))
203+ )
204+ #
205+ # Check the checkbox for 'nosy'
206+ self .driver .find_element (By .NAME , 'nosy' ).click ()
207+ print ("Test Case 2 -- success" )
208+
209+
210+
211+ class TestKeywords (unittest .TestCase ):
212+ def setUp (self ):
213+ # Initialize the Firefox driver with headless option setting to True.
214+ options = webdriver .FirefoxOptions ()
215+ options .add_argument ('--headless' )
216+
217+ self .driver = webdriver .Firefox (options = options )
218+
219+
220+
221+ def tearDown (self ):
222+ # Close the browser
223+ self .driver .quit ()
224+
225+ def test_demo1 (self ):
226+ # Open the URL
227+ self .driver .get ('http://localhost:8917/demo/' )
228+
229+ # Enter login credentials
230+ self .driver .find_element (By .NAME , '__login_name' ).send_keys ('admin' )
231+ self .driver .find_element (By .NAME , '__login_password' ).send_keys ('admin' )
232+
233+ # Submit the login form
234+ self .driver .find_element (By .CSS_SELECTOR , '.userblock > input:nth-child(12)' ).click ()
235+
236+ # Wait until the 'Create New' link is present and click on it
237+ WebDriverWait (self .driver , 10 ).until (
238+ EC .presence_of_element_located ((By .LINK_TEXT , 'Create New' ))
239+ )
240+ self .driver .find_element (By .LINK_TEXT , 'Create New' ).click ()
241+
242+ # Wait until the popup is loaded and click on the help link
243+ WebDriverWait (self .driver , 10 ).until (
244+ EC .presence_of_element_located ((By .CSS_SELECTOR , 'tr:nth-child(4) .classhelp' ))
245+ )
246+ #
247+ self .driver .find_element (By .CSS_SELECTOR , 'tr:nth-child(4) .classhelp' ).click ()
248+
249+ # Switch to the new window
250+ handles = self .driver .window_handles
251+ self .driver .switch_to .window (handles [- 1 ])
252+ # self.driver.maximize_window()
253+
254+ # Select keywords
255+ self .driver .find_element (By .XPATH , "//table[@id='popup-table']/tbody/tr[2]/td" ).click ()
256+ #
257+ self .driver .find_element (By .XPATH , "//table[@id='popup-table']/tbody/tr[3]/td" ).click ()
258+ #
259+ self .driver .find_element (By .XPATH , "//table[@id='popup-table']/tbody/tr[4]/td" ).click ()
260+ #
261+ self .driver .find_element (By .XPATH , "//table[@id='popup-table']/tbody/tr[2]/td" ).click ()
262+ #
263+ # Click on Apply
264+ self .driver .find_element (By .CSS_SELECTOR , "button:nth-child(3)" ).click ()
265+ #
266+ # Switch back to the original window
267+ self .driver .switch_to .window (handles [0 ])
268+
269+ # Wait until the new page is loaded
270+ WebDriverWait (self .driver , 10 ).until (
271+ EC .presence_of_element_located ((By .NAME , 'keyword' ))
272+ )
273+ #
274+
275+ # Check if the keyword input is filled with the selected keywords
276+ keyword_input = self .driver .find_element (By .NAME , "keyword" )
277+ self .driver .find_element (By .NAME , 'keyword' ).click ()
278+ print ("TestCase 1 -- success" )
279+
280+
281+ if __name__ == "__main__" :
282+ unittest .main ()
0 commit comments