赞
踩
pip install html-testRunner
# encoding = utf-8
'''
@Time : 2018/8/14 20:41
@Author : davieyang
@File : test_AjaxElement.py
@Software: PyCharm
'''
import traceback
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import unittest
import time
import HtmlTestRunner
class TestAjaxElement(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_AjaxDivOptionByKeys(self):
"""simulate keyboadr keydonw and enter and by circulating"""
url = 'http://www.sogou.com'
self.driver.get(url)
searchBox = self.driver.find_element_by_id('query')
searchBox.send_keys("selenium")
time.sleep(3)
for i in range(3):
searchBox.send_keys(Keys.DOWN)
time.sleep(3)
searchBox.send_keys(Keys.ENTER)
time.sleep(3)
def test_AjaxDivOptionByWords(self):
"""using xpath to fuzzy match"""
url = 'http://www.sogou.com'
self.driver.get(url)
try:
searchBox = self.driver.find_element_by_id('query')
searchBox.send_keys(u'光荣之路')
time.sleep(3)
suggetion_option = self.driver.find_element_by_xpath("//ul/li[contains(.,'@#')]")
suggetion_option.click()
time.sleep(3)
except NoSuchElementException as e:
print(traceback.print_exc())
def test_error(self):
""" This test should be marked as error one. """
raise ValueError
def test_fail(self):
""" This test should fail. """
self.assertEqual(1, 2)
@unittest.skip("This is a skipped test.")
def test_AjaxDivOptionByIndex(self):
"""using xpath to locate"""
url = 'http://www.sogou.com'
self.driver.get(url)
try:
searchBox = self.driver.find_element_by_id('query')
searchBox.send_keys(u'光荣之路')
time.sleep(3)
suggetion_option = self.driver.find_element_by_xpath("//*[@id='vl']/div[1]/ul/li[3]")
suggetion_option.click()
time.sleep(3)
except NoSuchElementException as e:
print(traceback.print_exc())
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='D:\\Programs\\Python\\PythonUnittest\\Reports\\'))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。