#关纯网项目需求500个电量文件以验证是否有删除逻辑,每小时在整点时会产生电量文件,正常要跑20天才能得到500个以上的电量文件
#这个程序以每5分钟调一次软件时间,只要3天就可以得到500个电量文件
#第一个for循20160501-0509(内置第一个for循01-09,第二个for循10-23)
#第二个for循20160510-0531
# -*- 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 Aaaaaa(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://192.168.100.40:8000/"
self.verificationErrors = []
self.accept_next_alert = True

def test_aaaaaa(self):
driver = self.driver
driver.get(self.base_url + "/ui/login/login.html#")
driver.maximize_window()
driver.find_element_by_id("user_account").clear()
driver.find_element_by_id("user_account").send_keys("admin")
driver.find_element_by_id("user_account").click()
driver.find_element_by_id("user_account").clear()
driver.find_element_by_id("user_account").send_keys("admin")
driver.find_element_by_id("hide_password").clear()
driver.find_element_by_id("hide_password").send_keys("1")
driver.find_element_by_id("loginBtn").click()
#设置界面
driver.find_element_by_id("setting").click()
for i in range(1,10):
#日期设置
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
time.sleep(2)
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("2016-05-0%d"%i).click()
print("2016-05-0%d"%i)
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
time.sleep(2)
driver.find_element_by_link_text("00").click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
time.sleep(2)
driver.find_element_by_link_text("00").click()
print("00 00")
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#点击弹出框
driver.switch_to.default_content()
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()
for j in range(1,10):
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
time.sleep(2)
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
driver.find_element_by_link_text("0%d"%j).click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
driver.find_element_by_link_text("00").click()
print("0%d 00"%j)
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#退出frame,点击弹出框
driver.switch_to.default_content()
time.sleep(2)
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()
#10点-23点
for k in range(10,24):
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
time.sleep(2)
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
driver.find_element_by_link_text("%d"%k).click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
driver.find_element_by_link_text("00").click()
print("%d 00"%k)
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#点击弹出框
driver.switch_to.default_content()
time.sleep(2)
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()
#5月10-5月31
for l in range(10,32):
#日期设置
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
time.sleep(2)
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("2016-05-%d"%l).click()
print("2016-05-%d"%l)
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
time.sleep(2)
driver.find_element_by_link_text("00").click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
time.sleep(2)
driver.find_element_by_link_text("00").click()
print("00 00")
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#点击弹出框
driver.switch_to.default_content()
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()
for m in range(1,10):
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
time.sleep(2)
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
driver.find_element_by_link_text("0%d"%m).click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
driver.find_element_by_link_text("00").click()
print("0%d 00"%m)
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#点击弹出框
driver.switch_to.default_content()
time.sleep(2)
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()
for n in range(10,24):
driver.find_element_by_xpath("//div[@id='settingDiv']/div/div/div/ul/li[2]/a/span").click()
#进入框
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
time.sleep(2)
#勾选修改日期和时间
driver.find_element_by_xpath("html/body/div[1]/div[2]/div[1]/h3/p/label").click()
time.sleep(2)
driver.find_element_by_id("hoursBtn").click()
driver.find_element_by_link_text("%d"%n).click()
time.sleep(2)
driver.find_element_by_id("minutesBtn").click()
driver.find_element_by_link_text("00").click()
print("%d 00"%n)
time.sleep(2)
driver.find_element_by_id("saveDateBtn").click()
time.sleep(5)
#点击弹出框
driver.switch_to.default_content()
time.sleep(2)
driver.find_element_by_xpath("html/body/section/div/p/a").click()
asleep()

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()
self.assertEqual([], self.verificationErrors)

def asleep():
time.sleep(300)

if __name__ == "__main__":
unittest.main()