TA的每日心情 | 无聊 2017-11-18 09:26 |
---|
签到天数: 41 天 连续签到: 1 天 [LV.5]测试团长
|
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class Ets2(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://etspad.knoocrc.cn"
self.verificationErrors = []
self.accept_next_alert = True
def test_ets2(self):
driver = self.driver
driver.get(self.base_url)
driver.maximize_window()
driver.find_element_by_link_text(u"参与测评").click()
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"请输手机号码!", driver.find_element_by_css_selector("div.layui-layer-content").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientMobile").clear()
driver.find_element_by_name("clientMobile").send_keys("123456")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"请输正确的手机号码!", driver.find_element_by_css_selector("div.layui-layer-content").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientMobile").clear()
driver.find_element_by_name("clientMobile").send_keys("13000000029")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"请输入姓名!", driver.find_element_by_xpath("//*[@id='layui-layer10']/div[2]").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientName").clear()
driver.find_element_by_name("clientName").send_keys("123")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"姓名只能为中文!", driver.find_element_by_xpath("//*[@id=1layui-layer11']/div[2]").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientName").clear()
driver.find_element_by_name("clientName").send_keys("12@#aas")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"姓名只能为中文!", driver.find_element_by_xpath("//*[@id=1layui-layer11']/div[2]").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientName").clear()
driver.find_element_by_name("clientName").send_keys(u"啊")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"输入的姓名长度不能小于2!", driver.find_element_by_xpath("//*[@id='layui-layer12']/div[2]").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientName").clear()
driver.find_element_by_name("clientName").send_keys(u"啊少时诵诗书")
driver.find_element_by_class_name("btn").click()
driver.switch_to_alert().accept
try: self.assertEqual(u"输入的姓名长度不能超过5!", driver.find_element_by_xpath("//*[@id='layui-layer13']/div[2]").text)
except AssertionError as e: self.verificationErrors.append(e)
driver.find_element_by_class_name("layui-layer-btn0").click()
driver.find_element_by_name("clientName").clear()
driver.find_element_by_name("clientName").send_keys(u"少时诵诗书")
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
|
|