-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcart.py
More file actions
103 lines (81 loc) · 3.45 KB
/
Copy pathcart.py
File metadata and controls
103 lines (81 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
97
98
99
100
101
102
103
import pytest # pip install pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import unittest
from parameterized import parameterized # pip install parameterized
from helper_functions import readData
class Cart(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(10)
self.vars = {}
self.driver.get("https://shopee.vn/buyer/login")
self.driver.set_window_size(1323, 1025)
self.login()
def tearDown(self):
self.driver.quit()
def close_add(self):
try:
self.driver.find_element(
By.CSS_SELECTOR, ".home-popup__close-area").click()
except:
pass
else:
self.driver.find_element(
By.CSS_SELECTOR, ".home-popup__close-area").click()
finally:
pass
def getUserAccount(self, filename):
file = open(filename, "r")
account = file.readlines()
file.close()
return account
def login(self):
account = self.getUserAccount("./account.text")
loginField = self.driver.find_element(By.NAME, "loginKey")
loginField.click()
loginField.send_keys(account[0])
passwordField = self.driver.find_element(By.NAME, "password")
passwordField.click()
passwordField.send_keys(account[1])
self.driver.implicitly_wait(10)
passwordField.send_keys(Keys.RETURN)
self.driver.implicitly_wait(10)
self.close_add()
@parameterized.expand(readData("cart"))
def test_tC001001(self, no, value):
print('Run tests')
self.driver.find_element(
By.CSS_SELECTOR, '.image-carousel__item:nth-child(1) .home-category-list__category-grid:nth-child(1) .n-CE6j > .\_8YHYKq').click()
self.driver.execute_script("window.scrollTo(0,300)")
self.driver.find_element(
By.CSS_SELECTOR, '.image-carousel__item:nth-child(1) .ofs-carousel__item:nth-child(1) .ofs-carousel__cover-image').click()
self.driver.execute_script("window.scrollTo(0,711)")
self.driver.find_element(
By.CSS_SELECTOR, 'div:nth-child(3) > div > .shopee-header-section .col-xs-3:nth-child(1) .\_3ZU4Xu').click()
self.driver.find_element(
By.CSS_SELECTOR, '.flex:nth-child(1) > .flex > .product-variation:nth-child(1)').click()
self.driver.find_element(
By.CSS_SELECTOR, '.flex:nth-child(2) > .flex > .product-variation:nth-child(1)').click()
self.driver.find_element(
By.CSS_SELECTOR, '.CXBc4V').click()
self.driver.find_element(
By.CSS_SELECTOR, ".CXBc4V").send_keys(Keys.BACKSPACE)
self.driver.find_element(
By.CSS_SELECTOR, ".CXBc4V").send_keys(Keys.BACKSPACE)
self.driver.find_element(
By.CSS_SELECTOR, ".CXBc4V").send_keys(Keys.BACKSPACE)
self.driver.find_element(
By.CSS_SELECTOR, ".CXBc4V").send_keys(value)
self.driver.find_element(
By.CSS_SELECTOR, '.\_8ULUF3').click()
if __name__ == '__main__':
unittest.main()