-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathteiba_member_number.py
67 lines (55 loc) · 2.16 KB
/
teiba_member_number.py
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
#!python
import unittest
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
class TiebaSlogan(unittest.TestCase):
@classmethod
def setUpClass(self):
# start web driver, open a browser
self.driver = webdriver.Chrome()
def setUp(self):
# open web page
self.driver.get('https://tieba.baidu.com/index.html')
def test_windows(self):
# find element
search_box = self.driver.find_element_by_xpath('//*[@id="wd1"]')
search_box.send_keys('windows')
search_box.submit()
memNum = self.driver.find_element_by_class_name('card_menNum')
self.assertGreaterEqual(int(memNum.text.replace(',', '')), 106700)
def test_linux(self):
# find element
search_box = self.driver.find_element_by_xpath('//*[@id="wd1"]')
search_box.send_keys('linux')
search_box.submit()
memNum = self.driver.find_element_by_class_name('card_menNum')
self.assertGreaterEqual(int(memNum.text.replace(',', '')), 203900)
def test_taiwan(self):
with self.assertRaises(NoSuchElementException):
# find element
search_box = self.driver.find_element_by_xpath('//*[@id="wd1"]')
search_box.send_keys('taiwan')
search_box.submit()
self.driver.find_element_by_class_name('card_menNum')
self.assertGreaterEqual(int(memNum.text.replace(',', '')), 371700)
def test_taiwan_warning(self):
# find element
search_box = self.driver.find_element_by_xpath('//*[@id="wd1"]')
search_box.send_keys('taiwan')
search_box.submit()
slogan = self.driver.find_element_by_xpath(
'/html/body/div[2]/div/div[2]/div[1]/h2')
self.assertEqual(slogan.text, "抱歉,根据相关法律法规和政策,本吧暂不开放。")
def test_number(self):
# for loop to find the integral multiples of eight
pass
def tearDown(self):
# print("exit")
pass
@classmethod
def tearDownClass(self):
# close browser
self.driver.close()
if __name__ == "__main__":
unittest.main()