-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Case4.py
More file actions
96 lines (80 loc) · 3.45 KB
/
Copy pathTest_Case4.py
File metadata and controls
96 lines (80 loc) · 3.45 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
# Design a test that will click browse In the top nav, then click view all books.
# This should take you to the browse page.
#
# Click to clear any filters that are already set, and then click to set the 2021 filter for publication date.
# Following on from this, automate a test that will type the following words into the search bar, and
# check that all titles found include that search text.
# Python
# Paint
# Secure
# Tableau
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium .webdriver.support .wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time
#driver
driver = webdriver.Chrome(executable_path="C:/Users/faiz/Desktop/Packt/chromedriver-win64/chromedriver.exe")
driver.get("https://subscription.packtpub.com/login")
#Verifying title of the page
title = driver.title
if title == "Login | Packt Subscription":
print("Login Page loaded successfully")
else:
print("Login page does not loaded successfully")
driver.maximize_window()
#Login to Packt
driver.find_element_by_id("login-input-email").send_keys("faiz999888777@gmail.com")
time.sleep(2)
driver.find_element_by_id("login-input-password").send_keys("Qfaiz@1z")
time.sleep(2)
driver.find_element_by_xpath("//*[@id='login-form']/form/button[1]/span").click()
time.sleep(10)
print("Logged in successfully")
time.sleep(5)
#Cl̥ick browse
driver.find_element_by_xpath("//*[@id='packt-navbar']/div[1]/a").click()
print(driver.title) #Print title of the page
time.sleep(5)
#click on all books
driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[1]/footer[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[10]/a[1]").click()
time.sleep(5)
#clear filter
driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[1]/div[5]/div[1]/div[1]/button[1]").click()
time.sleep(10)
#select filter
driver.find_element(By.XPATH,"/html[1]/body[1]/div[1]/div[1]/div[5]/div[1]/div[1]/button[1]").click()
time.sleep(10)
#select filter
publication_date = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "(//div[@class='header'])[3]")))
if publication_date.is_enabled():
publication_date.click()
time.sleep(5)
year =WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "(//div[normalize-space()='2021'])[1]")))
if year.is_enabled():
year.click()
time.sleep(5)
# Check keywords in search bar
search =['Python' ,'Paint' ,'Secure' ,'Tableau']
for item in search:
Searchbar = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "(//input[@name='query'])[1]")))
if Searchbar.is_enabled():
Searchbar.click()
Searchbar.send_keys(item)
time.sleep(5)
Search = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "(//i[@class='fa fa-search'])[1]")))
if Search.is_enabled():
Search.click()
time.sleep(5)
Searchfilter= WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "(//input[@placeholder='Search titles …'])[2]")))
value = Searchfilter.get_attribute("value")
#print(value)
#comparing search result
if value == item:
print(item, 'Keyword applied successfully')
else:
print(item, " Keyword not applied")
driver.quit()