from selenium.webdriver.common.by import By from Discuz.pageobjects.BasePage import BasePage import time from Discuz.framework.logger import Logger logger=Logger(logger="testDiscuz4").getlog() class testDiscuz4(BasePage): FaNewTie=(By.CSS_SELECTOR,"#newspecial") #发新帖 vote=(By.LINK_TEXT,"发起投票") #发起投票 TextKuang=(By.CSS_SELECTOR,".bm .pbt .z input") #输入文本标题 text1=(By.CSS_SELECTOR,".sinf div:nth-child(4) p:nth-child(1) input") #输入选项1 text2=(By.CSS_SELECTOR,".sinf div:nth-child(4) p:nth-child(2) input") #输入选项2 voteBtn=(By.CSS_SELECTOR,".bm .mtm span") #发起投票按钮 theme=(By.CSS_SELECTOR,".ts span") #主题名称 compare1=(By.CSS_SELECTOR,".pcht tbody tr:nth-child(2) td:nth-child(3)") #比例1 compare2= (By.CSS_SELECTOR, ".pcht tbody tr:nth-child(2) td:nth-child(3)") #比例2 option_1=(By.CSS_SELECTOR,"#option_1") #单选1 option_2 = (By.CSS_SELECTOR, "#option_2") #单选2 Name1=(By.CSS_SELECTOR,".pcht tr:nth-child(1) label") #单选姓名1 Name2=(By.CSS_SELECTOR,".pcht tr:nth-child(3) label") #单选姓名2 #单选姓名2 sumbit=(By.CSS_SELECTOR,"#pollsubmit") def EditTieZi(self,title,content1,content2): time.sleep(3) self.click(*self.FaNewTie) self.click(*self.vote) time.sleep(3) self.sendkeys(title,*self.TextKuang) self.sendkeys(content1,*self.text1) self.sendkeys(content2,*self.text2) time.sleep(3) self.click(*self.voteBtn) def voteTieZi(self):
from Discuz.testsuites.base_testcase import BaseTestcase from Discuz.pageobjects.HomePage1 import testDiscuz1 from Discuz.pageobjects.HomePage2 import testDiscuz2 import unittest import time from Discuz.framework.logger import Logger logger=Logger(logger="DiscuzTest2").getlog() class DiscuzTest2(BaseTestcase): def test_discuz2(self): #管理员登录删帖及在管理中心建新的版块 login2= testDiscuz2(self.driver) time.sleep(1) login2.GLlogin("admin","ly951107") #管理员登录 login2.Delete() time.sleep(3) login2.build("ly951107") #进管理中心建立新模块(密码,板块名字) time.sleep(10) login3 = testDiscuz1(self.driver) login3.adminlogin("lxc", "lxc960301.") # 用户登录 login3.newModule() login3.faTie("12341234", "向前走向前走") # 发帖标题及内容 #普通用户登录 # def test_discuz21(self): if __name__=="__main__": unittest.main()
import os.path from configparser import ConfigParser from selenium import webdriver from Discuz.framework.logger import Logger logger = Logger(logger="BrowserEngine").getlog() class BrowserEngine(object): dir = os.path.dirname(os.path.abspath('.')) chrome_driver_path = dir + "/tools/chromedriver.exe" ie_driver_path = dir + "/tools/IBDriver.exe" firefox_driver_path = dir + "/tools/geckodriver.exe" def open_browser(self): #启动浏览器 config = ConfigParser() # 读取config文件 file_path = os.path.dirname( os.path.abspath('.')) + '/config/config.ini' config.read(file_path) browser = config.get("browserType", "browserName") print(browser) logger.info('选择的浏览器是%s' % browser) url = config.get('testServer', 'URL') print(url) if browser == "Firefox": self.driver = webdriver.Firefox(self.firefox_driver_path) logger.info("火狐") elif browser == "Chrome": self.driver = webdriver.Chrome(self.chrome_driver_path) logger.info("打开谷歌浏览器") else: self.driver = webdriver.Ie(self.ie_driver_path)