-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_ddt_csv.txt
54 lines (35 loc) · 1.48 KB
/
search_ddt_csv.txt
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
import unittest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from time import sleep
import csv
from ddt import ddt, data, unpack
@ddt
class SearchDDT(unittest.TestCase):
def setUp(self):
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
s = Service(ChromeDriverManager().install())
self.driver = webdriver.Chrome(service = s, options = options)
driver = self.driver
driver.get('http://demo-store.seleniumacademy.com/')
# driver.find_element(By.LINK_TEXT,"Sortable Data Tables")
@data(('dress',6),('music',5))
@unpack
def test_search_ddt(self, search_value, expected_count):
driver = self.driver
search_field = driver.find_element(By.NAME,'q')
search_field.clear()
search_field.send_keys(search_value)
search_field.submit()
products = driver.find_elements(By.XPATH,'//h2[@class ="product-name"]/a')
print(f'Found {len(products)} products')
for product in products:
print(product.text)
self.assertEqual(expected_count,len(products))
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main(verbosity = 2)