#coding = utf-8
import unittest
from selenium import webdriver
from config import config
import time
check_melons = "//input[@value='melons']"
submit = "//input[@value= 'submit']"
melons = "melons"
class Test(unittest.TestCase):
def setUp(self):
url = config().getConfig("url")
self.driver = webdriver.Chrome()
self.driver.get(url)
def tearDown(self):
self.driver.quit()
def test1(self):
time.sleep(2)
self.driver.find_element_by_xpath("//*[@name='wd']").clear()
self.driver.find_element_by_xpath("//input[@name='wd' and @id='kw']").send_keys("English")
self.driver.find_element_by_xpath("//input[@value= '百度一下']").click()
time.sleep(2)
melon = config().getConfig("melon")
self.assertIn(melon, self.driver.page_source)
# def test2(self):
# time.sleep(2)
# self.driver.find_element_by_xpath(check_melons).click()
# time.sleep(3)
# self.driver.find_element_by_xpath(submit).click()
# time.sleep(2)
#
# self.assertIn("melons", self.driver.page_source)
if __name__ == '__main__':
unittest.main()
# coding=utf-8
import ConfigParser
class config():
def __init__(self):
config_path = "config/test.ini"
self.conf=ConfigParser.ConfigParser()
self.conf.read(config_path)
def getConfig(self,item):
return self.conf.get("test",item)
[test]
url = https://www.baidu.com
melon = "English"