-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
957 lines (793 loc) · 37.5 KB
/
Copy pathtesting.py
File metadata and controls
957 lines (793 loc) · 37.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, TimeoutException
# Initialize WebDriver
driver = webdriver.Chrome()
driver.maximize_window()
# these are the user credentials
username = 'abcd@gmail.com' #replace it with actual email
password = 'abcd&88' #replace it with actual password
pid = 'abcd' #replace it with actual pinterest id
user = "Ab Cd" #replace it with actual user name
# Hardcoded test data
website = 'https://www.pinterest.com/login/'
img_path = r"path/to/image" #replace it with actual image path
try:
# Step 1: Navigate to the website
driver.get(website)
print("Navigated to website")
# Check if we are on the Pinterest login page
assert "Pinterest" in driver.title
print("Title check passed")
# Step 2: Locate and interact with web elements to log in
try:
# Find the username and password fields
username_field = driver.find_element(By.ID, "email")
password_field = driver.find_element(By.ID, "password")
print("Located username and password fields")
# Enter the username and password
username_field.send_keys(username)
password_field.send_keys(password)
password_field.send_keys(Keys.RETURN)
print("Entered username and password")
# Wait for login to complete
time.sleep(5)
print("Login process initiated")
# Assert login was successful by checking the presence of a known post-login element
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="HeaderContent"]/div/div/div[2]/div/div/div/div[1]'))
)
print("Test Passed: Login successful.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
#test case 1 - to create a pin
try:
pin_title = "Test Pin"
create_button_xpath = '/html/body/div[1]/div/div[1]/div/div[1]/div[2]/div/div/div[2]/div/div/div/div[4]/div/a/div/div/span'
create_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, create_button_xpath))
)
print("Testing Create button")
create_button.click()
time.sleep(3) # Adjust as needed
print("Successfully tested Create button")
except TimeoutException:
print("Timeout while testing Create button")
except NoSuchElementException as e:
print(f"Element not found while testing Create button - {e}")
except Exception as e:
print(f"An error occurred while testing Create button - {e}")
# Step 4: Navigate to create pin page
try:
# Upload an image
image_upload_button_xpath = '//input[@type="file"]'
image_upload_button = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, image_upload_button_xpath))
)
image_upload_button.send_keys(img_path)
print("Uploaded image")
time.sleep(10) # Increased wait time for image upload
# Enter pin title
title_field_xpath = '//input[@id="storyboard-selector-title"]'
title_field = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, title_field_xpath))
)
title_field.send_keys(pin_title)
print("Entered pin title")
# Save the pin
publish_button_xpath = '//button[contains(@class, "RCK Hsu USg adn NTm KhY iyn oRi lnZ wsz") and .//div[text()="Publish"]]'
publish_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, publish_button_xpath))
)
publish_button.click()
print("Test case 1 Passed: Pin published successfully")
except TimeoutException:
print("Timeout while creating pin")
except NoSuchElementException as e:
print(f"Element not found while creating pin - {e}")
except Exception as e:
print(f"An error occurred while creating pin - {e}")
#test case 2 - delete a created pin
# Step 4: Delete the created pin
try:
time.sleep(5)
print("Navigating to home page")
driver.get('https://www.pinterest.com/')
# profile_icon = WebDriverWait(driver, 30).until(
# EC.element_to_be_clickable((By.XPATH, f"//a[@href='/{pid}/'"))
# )
profile_icon = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, f"//a[@href='/{pid}/']"))
)
profile_icon.click()
print("Navigated to 'Profile' page")
time.sleep(5)
# Locate and click the "Created" link
# created_link_xpath = f'//a[contains(@href, "/{pid}/_created/") and contains(@class, "Wk9 xQ4 S9z DUt CCY kVc Tbt L4E e8F BG7")]'
created_link_xpath = f'//a[contains(@href, "/{pid}/_created/")]'
created_link = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, created_link_xpath))
)
created_link.click()
print("Clicked on 'Created' link")
# Wait for the created section to load
time.sleep(5) # Adjust the delay as needed
print("Navigated to the 'Created' section")
pin_link_xpath = '//div[@data-test-id="story-pin-image-box"]/div/img'
pin_link = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, pin_link_xpath))
)
pin_link.click()
print("Navigated to the pin page")
# Locate and click the "More options" button
more_options_button_xpath = '//button[@aria-label="More options"]'
more_options_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, more_options_button_xpath))
)
more_options_button.click()
print("Clicked 'More options' button")
# Locate and click the "Edit Pin" option
edit_pin_option_xpath = '//div[@data-test-id="pin-action-dropdown-edit-pin"]'
edit_pin_option = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, edit_pin_option_xpath))
)
edit_pin_option.click()
print("Clicked 'Edit Pin' option")
# Locate and click the "Delete" button
delete_button_xpath = '//div[@data-test-id="delete-pin-button"]//button'
delete_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, delete_button_xpath))
)
delete_button.click()
print("Clicked 'Delete' button")
# Confirm the deletion by clicking the final "Delete" button
# Locate and click the confirm delete button
confirm_delete_button_xpath = '//div[@data-test-id="confirm-delete-pin"]//div[@data-test-id="submit-button"]//button[@type="submit"]'
confirm_delete_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, confirm_delete_button_xpath))
)
confirm_delete_button.click()
print("Test case 2 passed: Deleted the created pin")
#test case 3 - navigate to settings page
driver.get('https://www.pinterest.com/')
# Locate the "Accounts and more options" button and click it
accounts_options_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//div[@data-test-id='header-accounts-options-button']"))
)
accounts_options_button.click()
print("Clicked 'Accounts and more options' button")
# Wait for options menu to be displayed
time.sleep(5) # Adjust this delay if necessary
# Locate and click the "Settings" button
settings_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//div[@data-test-id='header-menu-options-settings']"))
)
settings_button.click()
print("Clicked 'Settings' button")
# Validate that the settings page is displayed
WebDriverWait(driver, 10).until(
EC.url_contains("settings")
)
print("Test case 3 Passed: Successfully navigated to the settings page")
#test case 4 - accounts and more option
#Locate the "Accounts and more options" button using XPath
driver.get('https://www.pinterest.com/')
accounts_options_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//div[@data-test-id='header-accounts-options-button']"))
)
print("Accounts and more options button located")
accounts_options_button.click()
print("Clicked 'Accounts and more options' button")
# Wait for options menu to be displayed
options_menu = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, "//div[contains(@class, 'XiG DHH kFh Dl7 V0G ho-')]")) # Update this based on actual menu content
)
print("Options menu located")
# Validate that the options menu is displayed
if options_menu:
print("Test case 4 Passed: Successfully navigated to accounts and more options menu.")
else:
print("Test Failed: Options menu not displayed.")
#test case 5 - notifications
# Locate the "Notifications" icon using aria-label attribute and class names
driver.get('https://www.pinterest.com/')
notifications_icon = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Notifications' and contains(@class, 'S9z') and contains(@class, 'INd')]"))
)
notifications_icon.click()
print("Clicked 'Notifications' icon")
# Wait for the notifications dropdown or page to be displayed
time.sleep(5) # Adjust this delay if necessary
# Validate that the notifications section or dropdown is displayed
# Use appropriate selector here if available; for now, assuming some identification is needed
notifications_dropdown = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, "//*[contains(@class, 'VxL _he ho- imm ojN p6V wc1 zI7 iyn Hsu')]"))
)
if notifications_dropdown:
print("Test case 5 Passed: Successfully navigated to notifications dropdown.")
else:
print("Test Failed: Notifications dropdown not displayed.")
#test case 6 - Profile page navigation
# Navigate to the profile page (assumes the user is on the homepage)
driver.get('https://www.pinterest.com/')
time.sleep(10)
profile_icon = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, f"//a[@href='/{pid}/']"))
)
profile_icon.click()
print("Clicked 'Profile' icon")
# Wait for profile page or dropdown to be displayed
time.sleep(5) # Adjust this delay if necessary
# Wait for profile page to load and validate
# profile_page = WebDriverWait(driver, 30).until(
# EC.presence_of_element_located((By.XPATH, "//div[@data-test-id='profile-name']"))
# )
profile_name = driver.find_element(By.XPATH, "//div[@data-test-id='profile-name']").text
if profile_name == user:
print("Test case 6 Passed: Successfully navigated to profile page.")
else:
print("Test Failed: Profile page not displayed or profile name does not match.")
#test case 7 - to click and comment
# Step 3: Locate and click on a photo from the grid
try:
driver.get('https://www.pinterest.com/')
time.sleep(10)
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Successfully clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
# Step 6: Find and interact with the comment box
try:
# Locate the comment box using its `data-test-id` attribute
comment_box_xpath = '//div[@data-test-id="comment-editor-container"]//div[@contenteditable="true"]'
comment_box = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, comment_box_xpath))
)
print("Testing comment box interaction")
comment_box.click()
time.sleep(8) # Wait for the comment box to be interactable
# Input a comment
comment_text = "waaawwww"
comment_box.send_keys(comment_text)
print("Test case 7 passed: Entered comment text")
except TimeoutException:
print("Timeout while interacting with comment box")
except NoSuchElementException as e:
print(f"Element not found while interacting with comment box - {e}")
except Exception as e:
print(f"An error occurred while interacting with comment box - {e}")
#test case 8 - click and follow
try:
driver.get('https://www.pinterest.com/')
time.sleep(10)
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Successfully clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
# Step 5: Click on the Follow button
try:
time.sleep(10)
# Locate and click on the follow button
follow_button_xpath = '//button[@aria-label="Follow"]'
follow_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, follow_button_xpath))
)
print("Testing Follow button click")
follow_button.click()
time.sleep(5) # Adjust as needed
print("Test case 8 passed: Successfully followed")
except TimeoutException:
print("Timeout while clicking on Follow button")
except NoSuchElementException as e:
print(f"Element not found while clicking on Follow button - {e}")
except Exception as e:
print(f"An error occurred while clicking on Follow button - {e}")
#test case 9 - click and save
# Step 3: Locate and click on a photo from the grid
try:
driver.get('https://www.pinterest.com/')
time.sleep(10)
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Successfully clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
# Step 4: Save the post
try:
# Locate and click on the save button
save_button_xpath = '//button[@aria-label="Save"]'
save_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, save_button_xpath))
)
print("Testing Save button click")
save_button.click()
time.sleep(5) # Adjust as needed
print("Test case 9 passed: Successfully saved the post")
except TimeoutException:
print("Timeout while clicking on Save button")
except NoSuchElementException as e:
print(f"Element not found while clicking on Save button - {e}")
except Exception as e:
print(f"An error occurred while clicking on Save button - {e}")
#test case 10 - click and react
time.sleep(10)
# Step 3: Locate and click on a photo from the grid
try:
driver.get('https://www.pinterest.com/')
time.sleep(10)
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Successfully clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
# Step 4: Save the post
try:
# Locate and click on the save button
save_button_xpath = '//div[@aria-label="React"]//div[@data-test-id="react-button"]'
save_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, save_button_xpath))
)
print("Testing React button click")
save_button.click()
time.sleep(5) # Adjust as needed
print("Test case 10 passed: Successfully reacted to a post")
except TimeoutException:
print("Timeout while clicking on react button")
except NoSuchElementException as e:
print(f"Element not found while clicking on react button - {e}")
except Exception as e:
print(f"An error occurred while clicking on react button - {e}")
#test case 11 - message
driver.get('https://www.pinterest.com/')
# Locate the "Messages" icon using aria-label attribute and class names
messages_icon = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Messages' and contains(@class, 'S9z') and contains(@class, 'INd')]"))
)
messages_icon.click()
print("Clicked 'Messages' icon")
# Wait for the messages dropdown or page to be displayed
time.sleep(5) # Adjust this delay if necessary
# Validate that the messages section or dropdown is displayed
# Use appropriate selector here if available; for now, assuming some identification is needed
messages_dropdown = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, '//div[@data-test-id="full-height-inbox-container"]'))
)
if messages_dropdown:
print("Test case 11 Passed: Successfully navigated to messages dropdown.")
else:
print("Test Failed: Messages dropdown not displayed.")
#test case 12 - search and click
try:
driver.get('https://www.pinterest.com/')
search_box_xpath = '//input[@data-test-id="search-box-input"]'
search_box = WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.XPATH, search_box_xpath))
)
print("Testing Search box")
search_box.click()
search_box.send_keys("laptop")
search_box.send_keys(Keys.RETURN)
time.sleep(5) # Adjust as needed
print("Successfully tested Search box with keyword 'laptop'")
except TimeoutException:
print("Timeout while testing Search box")
except NoSuchElementException as e:
print(f"Element not found while testing Search box - {e}")
except Exception as e:
print(f"An error occurred while testing Search box - {e}")
try:
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Test case 12 passed: Successfully searched and clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
#test case 13 - search, click and save
# Step 3: Find the search box using full XPath, enter "laptop", and test it
try:
driver.get('https://www.pinterest.com/')
search_box_xpath = '//input[@data-test-id="search-box-input"]'
search_box = WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.XPATH, search_box_xpath))
)
print("Testing Search box")
search_box.click()
search_box.send_keys("laptop")
search_box.send_keys(Keys.RETURN)
time.sleep(5) # Adjust as needed
print("Successfully tested Search box with keyword 'laptop'")
except TimeoutException:
print("Timeout while testing Search box")
except NoSuchElementException as e:
print(f"Element not found while testing Search box - {e}")
except Exception as e:
print(f"An error occurred while testing Search box - {e}")
try:
# Find a photo using the `data-test-id` attribute
photo_xpath = '//div[@data-test-id="non-story-pin-image"]/div/img'
photo = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, photo_xpath))
)
print("Testing photo click")
photo.click()
time.sleep(5) # Wait for photo to open
print("Successfully clicked on the photo")
except TimeoutException:
print("Timeout while clicking on photo")
except NoSuchElementException as e:
print(f"Element not found while clicking on photo - {e}")
except Exception as e:
print(f"An error occurred while clicking on photo - {e}")
# Step 4: Save the post
try:
# Locate and click on the save button
save_button_xpath = '//button[@aria-label="Save"]'
save_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, save_button_xpath))
)
print("Testing Save button click")
save_button.click()
time.sleep(5) # Adjust as needed
print("Test case 13 passed: Successfully searched and saved the post")
except TimeoutException:
print("Timeout while clicking on Save button")
except NoSuchElementException as e:
print(f"Element not found while clicking on Save button - {e}")
except Exception as e:
print(f"An error occurred while clicking on Save button - {e}")
#test case 14 - search
#Step 3: Find the search box using full XPath, enter "laptop", and test it
try:
driver.get('https://www.pinterest.com/')
search_box_xpath = '//input[@data-test-id="search-box-input"]'
search_box = WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.XPATH, search_box_xpath))
)
print("Testing Search box")
search_box.click()
search_box.send_keys("laptop")
search_box.send_keys(Keys.RETURN)
time.sleep(5) # Adjust as needed
print("Test case 14 passed: Successfully tested Search box with keyword 'laptop'")
except TimeoutException:
print("Timeout while testing Search box")
except NoSuchElementException as e:
print(f"Element not found while testing Search box - {e}")
except Exception as e:
print(f"An error occurred while testing Search box - {e}")
except Exception as e:
print(f"An error occurred - {e}")
finally:
# Step 5: Close the browser session
logout_path1 = '//div[@data-test-id="header-accounts-options-button"]'
logout_button1 = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, logout_path1))
)
logout_button1.click()
logout_path2 = '//div[@data-test-id="header-menu-options-logout"]'
logout_button2 = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, logout_path2))
)
logout_button2.click()
print("Log out successful ")
driver.quit()
print("Closed the browser session")
#test case 15 - explore
try:
driver = webdriver.Chrome()
print("Testing Explore")
# Step 1: Open the Pinterest webpage
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
time.sleep(5) # Wait for the page to load
# Step 2: Test the "Explore" button
try:
explore_button_xpath = '//a[@href="/ideas/"]'
explore_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, explore_button_xpath))
)
print("Testing Explore button")
explore_button.click()
time.sleep(3) # Wait for the page to load
print("Test case 15 passed: Successfully tested Explore button")
except TimeoutException:
print("Timeout while testing Explore button")
except NoSuchElementException as e:
print(f"Element not found while testing Explore button - {e}")
finally:
driver.quit()
print("Closed the browser session")
#test case 16 - login test
try:
driver = webdriver.Chrome()
user = 'abcd@gmail.com'
passwrd = 'gjgydguyw'
# Step 3: Navigate to the website
driver.get(website)
print("Navigated to website")
# Check if we are on the Pinterest login page
assert "Pinterest" in driver.title
print("Title check passed")
# Step 4: Locate and interact with web elements
try:
# Find the username and password fields
username_field = driver.find_element(By.ID, "email")
password_field = driver.find_element(By.ID, "password")
print("Located username and password fields")
# Enter the username and password
username_field.send_keys(user)
password_field.send_keys(passwrd)
password_field.send_keys(Keys.RETURN)
print("Entered username and password")
# Wait for the page to load and check for the profile icon
time.sleep(5) # Adjust sleep time if necessary
# Check for a known element after login (e.g., search bar)
try:
driver.find_element(By.NAME, "searchBoxInput") # Example element after login
print("Test case 16 Passed: Login successful.")
except NoSuchElementException:
print("Test case 16 Passed: Login unsuccessful.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
finally:
# Step 6: End the session
driver.quit()
print("Closed the browser session")
#test case 17 - about page
def test_about_button(driver):
try:
driver = webdriver.Chrome()
# Navigate to Pinterest website
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
# Wait until the About button is visible and interactable
about_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="__PWS_ROOT__"]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/a'))
)
print("Located About button on Pinterest homepage")
# Get the current window handle (to switch back later)
main_window = driver.current_window_handle
# Click on the About button
about_button.click()
print("Clicked on About button")
# Wait for the new tab to open and switch to it
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) # Wait until two windows are open
for handle in driver.window_handles:
if handle != main_window:
driver.switch_to.window(handle)
break
# Wait for the About page to load (you can add more specific waits if necessary)
time.sleep(5)
# Get the page title for debugging
page_title = driver.title
print(f"About page title: {page_title}")
# Example assertion: Check if the page title contains 'About Pinterest'
# assert "About Pinterest" in page_title
print("Test case 17 Passed: Successfully navigated to About page.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}. Page title was: {page_title}")
finally:
# Close the new tab and switch back to the main window
driver.close()
driver.switch_to.window(main_window)
print("Closed the new tab and switched back to the main window")
# Call the function to test the About button
test_about_button(driver)
#test case 18 - blog page
def test_blog_button(driver):
try:
driver = webdriver.Chrome()
# Navigate to Pinterest website
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
# Wait until the Blog button is visible and interactable
blog_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="__PWS_ROOT__"]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[3]/div/a'))
)
print("Located Blog button on Pinterest homepage")
# Get the current window handle (to switch back later)
main_window = driver.current_window_handle
# Click on the Blog button
blog_button.click()
print("Clicked on Blog button")
# Wait for the new tab to open and switch to it
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) # Wait until two windows are open
for handle in driver.window_handles:
if handle != main_window:
driver.switch_to.window(handle)
break
# Example of further actions:
# You can add assertions or further interactions with elements on the Blog page
time.sleep(7)
# Example assertion: Check if the page title contains 'Blog'
# assert "Blog" in driver.title
print("Test case 18 Passed: Successfully navigated to Blog page.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
finally:
# Close the new tab and switch back to the main window
driver.close()
driver.switch_to.window(main_window)
print("Closed the new tab and switched back to the main window")
# Call the function to test the Blog button
test_blog_button(driver)
#test case 19 - businesses page
def test_businesses_button(driver):
try:
driver = webdriver.Chrome()
# Navigate to Pinterest website
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
# Wait until the Businesses button is visible and interactable
businesses_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="__PWS_ROOT__"]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[2]/div/a'))
)
print("Located Businesses button on Pinterest homepage")
# Get the current window handle (to switch back later)
main_window = driver.current_window_handle
# Click on the Businesses button
businesses_button.click()
print("Clicked on Businesses button")
# Wait for the new tab to open and switch to it
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) # Wait until two windows are open
for handle in driver.window_handles:
if handle != main_window:
driver.switch_to.window(handle)
break
# Example of further actions:
# You can add assertions or further interactions with elements on the "Businesses" page
# Example assertion: Check if the page title contains 'Business'
assert "Business" in driver.title
print("Test case 19 Passed: Successfully navigated to Businesses page.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
finally:
# Close the new tab and switch back to the main window
driver.close()
driver.switch_to.window(main_window)
print("Closed the new tab and switched back to the main window")
# Call the function to test the Businesses button
test_businesses_button(driver)
#test case 20 - today page
def test_today_button(driver):
try:
driver = webdriver.Chrome()
# Navigate to Pinterest website
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
# Wait until the Today button is visible and interactable
today_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/today/')]"))
)
print("Located Today button on Pinterest homepage")
# Click on the Today button
today_button.click()
print("Clicked on Today button")
# Wait for the page to load (you can add more specific waits if necessary)
time.sleep(5)
# Example of further actions:
# You can add assertions or further interactions with elements on the "Today" page
# Example assertion: Check if the page title contains 'Today'
assert "Today" in driver.title
print("Test case 20 Passed: Successfully navigated to Today page.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
finally:
# End the session
driver.quit()
print("Closed the browser session")
# Call the function to test the Today button
test_today_button(driver)
#test case 21 - watch button
def test_watch_button(driver):
try:
driver = webdriver.Chrome()
# Navigate to Pinterest website
driver.get('https://www.pinterest.com/')
print("Navigated to Pinterest website")
# Wait until the Watch button is visible and interactable
watch_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="__PWS_ROOT__"]/div/div[1]/div/div[1]/div/div[1]/div[3]/a/div/div/span'))
)
print("Located Watch button on Pinterest homepage")
# Click on the Watch button
watch_button.click()
print("Clicked on Watch button")
# Wait for the page to load (you can add more specific waits if necessary)
time.sleep(5)
# Example of further actions:
# You can add assertions or further interactions with elements on the "Watch" page
# Example assertion: Check if the page title contains 'Watch'
assert "Watch" in driver.title
print("Test case 21 Passed: Successfully navigated to Watch page.")
except NoSuchElementException as e:
print(f"Test Failed: Element not found - {e}")
except TimeoutException as e:
print(f"Test Failed: Timeout - {e}")
except AssertionError as e:
print(f"Test Failed: Assertion error - {e}")
finally:
# End the session
driver.quit()
print("Closed the browser session")
# Call the function to test the Watch button
test_watch_button(driver)