selenium+python笔记10

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等
"""
import unittest
import os
import sys
from selenium import webdriver cur_dir = os.getcwd()
sys.path.append(cur_dir.split(r'\test_case')[0]) from public import login # from selenium.webdriver.common.keys import Keys
import time class TestDel(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.126.com/"
self.verificationErrors = []
self.accept_next_alert = True # 搜索邮件
def test_del_mail(self):
driver = self.driver
driver.get(self.base_url)
# 调用登录模块
login.login(self, 'xxxx', 'xxxx')
# 打开收件箱
driver.find_element_by_class_name('nui-tree-item-text').click()
time.sleep(2)
driver.find_elements_by_xpath("//span[@class='nui-chk-symbol']/b").pop(1).click()
try:
spans = driver.find_elements_by_tag_name('span')
for s in spans:
if s.text == u'删 除':
s.click()
except:
pass
# 断言是否已删除
text = driver.find_element_by_css_selector("span.nui-tips-text>a").text
self.assertEqual(text, u'已删除')
# 退出
login.logout(self) def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
unittest.main()
上一篇:selenium+python笔记8


下一篇:idea 14运行java工程报错-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.