def test_cash_expenditure(self): """现金记账支出测试用例""" logging.info("test_cash_expenditure start....") driver = self.driver driver.get(self.base_url) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys("admin") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("123456") driver.find_element_by_id("submit").click() driver.find_element_by_id("submit").click() time.sleep(3) ##现金记账 driver.find_element_by_xpath( "//*[@id=\"s-menu-allapps\"]/button").click() time.sleep(3) driver.find_element_by_xpath('//*[@id="s-applist-3"]/a').click() time.sleep(5) ##进入ifarme driver.switch_to.frame("iframe-3") time.sleep(5) ##点击支出 driver.find_element_by_xpath( '//*[@id="mainNavbar"]/div[2]/ul/li[4]/a').click() ##点击记支出 driver.find_element_by_xpath('//*[@id="menuActions"]/a[2]').click() time.sleep(3) driver.find_element_by_id('depositor').click() ##选择账号 driver.find_element_by_xpath('//*[@id="depositor"]/option[2]').click() driver.find_element_by_id('category').click() ##选择科目 driver.find_element_by_xpath('//*[@id="category"]/option[2]').click() driver.find_element_by_id('objectType2').click() ##选择订单支出 time.sleep(2) driver.find_element_by_xpath( '//*[@id="order_chosen"]/a').click() ##选择订单 driver.find_element_by_xpath( '//*[@id="order_chosen"]/div/ul/li[1]').click() time.sleep(2) driver.find_element_by_id('money').clear() ##清空金额 driver.find_element_by_id('money').send_keys(random.randint( 3211, 5462)) ##输入金额 driver.find_element_by_xpath( '//*[@id="handlers_chosen"]/ul').click() ##选择经手人 driver.find_element_by_xpath( '//*[@id="handlers_chosen"]/div/ul/li[1]').click() driver.find_element_by_id('desc').send_keys('我们我们啊哈哈') ##输入说明 driver.find_element_by_id('submit').click() ##保存 time.sleep(3) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("test_cash_expenditure end....") time.sleep(5)
def test_user_login_test(self, admin, password, flag): """admin的登录的所有测试用例 测试用例在讲一个故事: 1.条件是什么? 2.做了哪些操作? 3.出现了什么结果? """ logging.info("test_admin_login_test start....") driver = self.driver driver.get(ADMIN_PAGE) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys(admin) driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys(password) driver.find_element_by_id("submit").click() time.sleep(3) self.assertIn(flag, driver.page_source) logging.info("test data is : {}, {}, {}".format(admin, password, flag)) capture_screen(driver) logging.info("test_user_login_test end....")
def test_create_new_products(self): """新建产品测试用例""" logging.info("test_create_new_products start....") driver = self.driver driver.get(self.base_url) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys("admin") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("123456") driver.find_element_by_id("submit").click() driver.find_element_by_id("submit").click() time.sleep(3) ##点击所有应用,点击客户管理 driver.find_element_by_xpath( "//*[@id=\"s-menu-allapps\"]/button").click() time.sleep(3) driver.find_element_by_xpath("//*[@id=\"s-applist-1\"]/a/img").click() time.sleep(3) ##进入ifarme driver.switch_to.frame('iframe-1') time.sleep(5) ##新增产品 driver.find_element_by_link_text("产品").click() time.sleep(5) driver.find_element_by_xpath( '//*[@id="menuActions"]/a').click() ##点击新增产品 driver.find_element_by_id("name").send_keys(random.randint( 1000, 9999)) ##输入名称 time.sleep(3) ##输入产品 driver.find_element_by_id("code").send_keys("{0}{1}".format( random.choice('abcdefghjklqwertyuiomnbvcxz'), random.randint(1000, 9999))) time.sleep(3) driver.find_element_by_id("line").click() ##选择产品线 time.sleep(3) driver.find_element_by_id("type").click() ##选择类型 driver.find_element_by_xpath('//*[@id="type"]/option[2]').click() driver.find_element_by_id("status").click() ##选择状态 driver.find_element_by_xpath('//*[@id="status"]/option[2]').click() driver.find_element_by_id('submit').click() ##点击保存 time.sleep(3) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("test_create_new_products end....")
def test_admin_login_test(self, admin, password, flag): """admin的登录的所有测试用例""" logging.info("test_admin_login_test start......") driver = self.driver driver.get(self.base_url + "/bugfree/index.php/site/login") driver.find_element_by_id("LoginForm_username").clear() driver.find_element_by_id("LoginForm_username").send_keys(admin) driver.find_element_by_id("LoginForm_password").clear() driver.find_element_by_id("LoginForm_password").send_keys(password) driver.find_element_by_id("LoginForm_rememberMe").click() driver.find_element_by_id("SubmitLoginBTN").click() # handles = driver.window_handles # driver.switch_to.window(handles[1]) time.sleep(3) self.assertIn(flag, driver.page_source) logging.info("test data is : {0},{1},{2}".format( admin, password, flag)) capture_screen(driver) # pic_path = capture_screen(driver) # if pic_path is None: # logging.error("截图不成功") # else: # logging.info(pic_path) logging.info("test_admin_login_test end......")
def test_create_new_order(self): """新增订单测试用例""" logging.info("test_create_new_order start....") driver = self.driver driver.get(self.base_url) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys("admin") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("123456") driver.find_element_by_id("submit").click() driver.find_element_by_id("submit").click() time.sleep(3) ##点击所有应用,点击客户管理 driver.find_element_by_xpath( "//*[@id=\"s-menu-allapps\"]/button").click() time.sleep(3) driver.find_element_by_xpath("//*[@id=\"s-applist-1\"]/a/img").click() time.sleep(3) ##进入iframe driver.switch_to.frame('iframe-1') time.sleep(5) ##新增订单 driver.find_element_by_link_text("订单").click() time.sleep(5) driver.find_element_by_xpath( '//*[@id="menuActions"]/a').click() ##创建订单 driver.find_element_by_xpath( '//*[@id="customer_chosen"]/a').click() ##选择客户 driver.find_element_by_xpath( '//*[@id="customer_chosen"]/div/ul/li[3]').click() time.sleep(2) driver.find_element_by_xpath( '//*[@id="product_chosen"]/ul').click() ##选择产品 time.sleep(3) driver.find_element_by_xpath( '//*[@id="product_chosen"]/div/ul/li[3]').click() driver.find_element_by_id('plan').send_keys(random.randint( 2123, 6454)) ##输入计划金额 time.sleep(5) driver.find_element_by_id('submit').click() ##点击保存 time.sleep(5) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("ttest_create_new_order end....")
def test_create_member(self): """添加成员测试用例""" logging.info("test_create_member start....") driver = self.driver driver.get(self.base_url) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys("admin") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("123456") driver.find_element_by_id("submit").click() driver.find_element_by_id("submit").click() time.sleep(3) ##点击后台管理 driver.find_element_by_xpath('//*[@id="s-menu-superadmin"]/button').click() time.sleep(3) ##进入ifarme driver.switch_to.frame('iframe-superadmin') time.sleep(5) ##点击添加成员 driver.find_element_by_xpath('//*[@id="shortcutBox"]/div/div[1]/div/a/h3').click() ##用户名 driver.find_element_by_id('account').send_keys("{0}{1}".format(random.choice('abcdefghjklqwertyuiomnbvcxz'),random.randint(1000,9999))) ##真实姓名 driver.find_element_by_id('realname').send_keys(random.choice('abcdefghjklqwertyuiomnbvcxz')) driver.find_element_by_id('gender2').click()##选择性别 driver.find_element_by_id('dept').click()##选择部门 driver.find_element_by_xpath('//*[@id="dept"]/option[2]').click() driver.find_element_by_id('role').click()##选择角色 driver.find_element_by_xpath('//*[@id="role"]/option[3]').click() driver.find_element_by_id('password1').send_keys('123456')##输入密码 driver.find_element_by_id('password2').send_keys('123456')##再一次输入密码 ##输入邮箱 driver.find_element_by_id('email').send_keys("{}@qq.com".format(random.randint(1000,9999))) driver.find_element_by_id('submit').click()##点击保存 time.sleep(6) ##删除成员信息 # driver.find_element_by_xpath('/html/body/div/div/div/div[2]/div/div/table/tbody/tr/td[11]/a[3]').click() # time.sleep(2) # alert = self.driver.switch_to.alert##获取警示框 # alert.accept()##点击确认 # time.sleep(3) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("test_create_member end....")
def test_create_new_clients(self): """新建客户测试用例""" logging.info("test_create_new_clients start....") driver = self.driver driver.get(ADMIN_PAGE) login_by_admin(driver) time.sleep(3) time.sleep(5) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("test_create_new_clients end....")
def test_disable_activation(self): """禁用成员、激活成员测试用例""" logging.info("test_create_member start....") driver = self.driver driver.get(self.base_url) driver.find_element_by_id("account").clear() driver.find_element_by_id("account").send_keys("admin") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("123456") driver.find_element_by_id("submit").click() driver.find_element_by_id("submit").click() time.sleep(3) ##点击后台管理 driver.find_element_by_xpath( '//*[@id="s-menu-superadmin"]/button').click() time.sleep(3) ##进入ifarme driver.switch_to.frame('iframe-superadmin') time.sleep(5) ##点击添加成员 driver.find_element_by_xpath( '//*[@id="shortcutBox"]/div/div[1]/div/a/h3').click() ##选择研发部门 driver.find_element_by_xpath('//*[@id="category5"]').click() ###禁用成员 driver.find_element_by_xpath( '/html/body/div/div/div/div[2]/div/div/table/tbody/tr[2]/td[11]/a[2]' ).click() time.sleep(5) ###激活成员 driver.find_element_by_xpath( '/html/body/div/div/div/div[2]/div/div/table/tbody/tr[2]/td[11]/a[2]' ).click() time.sleep(5) logging.info("test data is : {},{}".format('admin', '123456')) pic_path = capture_screen(driver) if pic_path is None: logging.error("截图不成功") else: logging.info(pic_path) logging.info("test_MemberConfiguration_test end....")