Пример #1
0
class TestAddProduct(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.login = LoginPage(self.driver)
        self.add = AddProduct(self.driver)

    def tearDown(self):
        self.driver.quit()

    def test_o1(self):
        '''新增产品'''
        result = self.login.login()
        self.assertTrue(result)
        p_name = str(time.time())
        p_code = str(time.time())
        self.add.addproduct(p_name, p_code)
        result = self.add.get_product_list_text()
        self.assertTrue(result == p_name)

    def test_02(self):
        '''新增重复产品'''
        result = self.login.login()
        self.assertTrue(result)
        p_name = str("admin02")
        p_code = str(time.time())
        self.add.addproduct(p_name, p_code)
        result = self.add.get_product_list_text()
        a = self.add.is_alert()
        result = a.text
        print(result)
        a.accept()
        self.assertFalse(
            result == "『产品名称』已经有『%s』这条记录了。如果您确定该记录已删除,请到后台管理-回收站还原。。" % p_name)
Пример #2
0
class TestAddBug(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()
        self.login = LoginPage(self.driver)
        self.add = AddBug(self.driver)

    def tearDown(self):
        self.driver.quit()

    def test_o1(self):
        '''提交bug'''
        result = self.login.login()
        self.assertTrue(result)
        timestr = str(time.time())
        self.add.addBug(timestr)
        result = self.add.new_get_text(timestr)
        # print('a', result)
        # print("b", timestr)
        self.assertTrue(result)

    def test_02(self):
        '''提交重复bug'''
        result = self.login.login()
        self.assertTrue(result)
        oldtitle = "add"
        self.add.addBug(oldtitle)
        time.sleep(2)
        alert = self.add.is_alert()
        result = alert.text
        time.sleep(3)
        alert.accept()
        self.assertTrue(result == "已有相同标题的Bug")
Пример #3
0
class ChanDAOLogin(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.Login = LoginPage(self.driver)

    def tearDown(self):
        self.driver.quit()

    @classmethod
    def setUpClass(cls):
        pass

    @classmethod
    def tearDownClass(cls):
        pass

    def test_loginsuccess(self):
        '''
        测试点:使用正确的用户名和密码登录成功
        检查点:登录成功跳转后页面存在登录用户名
        '''
        result = self.Login.login()
        self.assertTrue(result)
        print("登录成功用例——测试通过")

    def test_loginfail(self):
        '''
        测试点:使用错误的用户名和密码登录失败
        检查点:登录失败弹出登录失败弹框
        '''
        result = self.Login.login(user='******', passwd='123456')

        self.assertFalse(result)
        self.is_alert_exist()
        print("登录失败用例-测试通过")

    @unittest.skip  # 无条件跳过该用例
    def test_skip01(self):
        pass

    @unittest.skipIf(1 > 0, "表达式成立跳过")  # 表达式成立跳过
    def test_skip02(self):
        pass

    @unittest.skipUnless(1, "除非为真跳过")  # 除非为真跳过
    def test_skip03(self):
        pass

    def is_alert_exist(self):
        '''判断alert是不是在'''
        try:
            time.sleep(2)
            alert = self.driver.switch_to.alert
            text = alert.text
            alert.accept()  # 用alert 点alert
            return text
        except:
            return ""
Пример #4
0
 def setUp(self):
     self.driver = webdriver.Chrome()
     self.login = LoginPage(self.driver)
     self.add = AddProduct(self.driver)
Пример #5
0
        time.sleep(2)
        try:
            # self.click(self.loc_product_choose)
            # self.click(self.loc_admin_p)
            ele = self.findElements(self.loc_buglist)
            print(ele)
            t1 = ele[0].text
            print(t1)
            return t1
        except:
            return ''

    def new_get_text(self, _text):
        self.driver.maximize_window()
        r = self.is_text_in_element(self.loc_bug_first, _text=_text)
        return r


if __name__ == '__main__':
    import selenium.webdriver as webdriver
    driver = webdriver.Chrome()
    lo = LoginPage(driver)
    lo.login()
    add = AddBug(driver)
    timestr = str(time.time())
    print(timestr)
    add.addBug(timestr)
    r1 = add.new_get_text(timestr)
    print("新方法的结果: %s"% r1)
    assert r1 == timestr
    driver.quit()
Пример #6
0
    def get_product_list_text(self):
        try:
            self.driver.get("http://127.0.0.1:81/zentao/product")
            eles = self.findElements(self.loc_p_list)
            els = eles[0].text
            return els
        except:
            return ""

    def get_fist_name(self, _text):
        r = self.is_text_in_element(self.loc_p_first, _text=_text)
        return r




if __name__ == '__main__':
    import selenium.webdriver as webdriver
    d = webdriver.Chrome()
    lo = LoginPage(d)
    lo.login()
    a = AddProduct(d)
    a.addproduct("admin07", "007")
    result = a.get_product_list_text()
    print(result)
    assert  result == "admin07"
    print("测试通过!")
    d.quit()


Пример #7
0
 def setUp(self):
     self.driver = webdriver.Chrome()
     self.Login = LoginPage(self.driver)