コード例 #1
0
 def setUpClass(self):  # 每个用例执行之前执行
     print('开始执行用例')
     self.dr = webdriver.Chrome()
     self.dr.get('http://10.10.16.213/#/login')
     self.dr.implicitly_wait(15)
     # cls.dr.implicitly_wait(10)  # 在规定时间会自动搜索,超出时间,抛出异常(消耗时间是固定的)
     # 当使用了隐性等待执行测试的时候,如果 WebDriver没有在 DOM中找到元素,将继续等待,超出设定时间后则抛出找不到元素的异常
     # 相当于设置全局的等待,在定位元素时,对所有元素设置超时时间。隐式等待是等页面加载,而不是元素加载!!!(隐式等待就是针对页面的,显式等待是针对元素的。)
     self.dr.maximize_window()
     time.sleep(2)
     # 调用function.login方法’
     try:
         function.login(self, user_name="admin", password="******")
         time.sleep(1)
         # 断言是否登录成功
         print(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text)
     except:
         print("登录失败")
         # 截图
         function.error_png(self, 'test_1_login')
         self.assertEqual(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text, "Asset")
コード例 #2
0
 def test_2_login_fail(self, user_name, password):
     '''输入正确的用户名,错误的密码,登陆失败'''
     try:
         function.login(self, user_name, password)
         time.sleep(3)
         # 断言是否登录成功
         tt = self.dr.find_element_by_css_selector(
             ReadElement.Portal_ele(self, "Welcome标志定位")).text
         print(tt)
         self.assertEqual(tt, "WELCOME")
         cc = self.dr.find_element_by_xpath(
             '/html/body/div[3]/div/div/div[1]/div/span').text
         print(cc)
     except:
         tt = self.dr.find_element_by_css_selector(
             ReadElement.Portal_ele(self, "Welcome标志定位")).text
         print(tt)
         # 截图
         function.error_png(self, 'test_2_login_fail')
         self.assertEqual(tt, "WELCOME")
コード例 #3
0
 def test_1_login(self):
     '''输入正确的用户名,密码,登陆成功'''
     # function.open_tmx(self)
     # self.dr = self.driver
     try:
         function.login(self, ReadData.Basic_data(self, "TMX用户名"),
                        ReadData.Basic_data(self, "TMX密码"))
         time.sleep(1)
         # 断言是否登录成功
         self.assertEqual(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text, "Asset")
         print("登录成功")
     except:
         print("登录失败")
         # 截图
         function.error_png(self, 'test_1_login')
         self.assertEqual(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text, "Asset")
コード例 #4
0
    def test_3_ForgetPassword(self):
        '''用户名忘记密码'''

        try:
            self.dr.find_element_by_partial_link_text(
                ReadElement.Portal_ele(self, "忘记密码")).click()
            time.sleep(2)
            # tt=self.dr.find_element_by_css_selector(self,ReadElement.Portal_ele(self,"忘记密码Tip")).text
            # print(tt)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.Portal_ele(self, "忘记密码Tip")).text, "Tip")
            time.sleep(0.5)
            # class组合属性定位class中有空格用点“.”表示
            # self.dr.find_element_by_xpath("/html/body/div[3]/div[2]/div/div/div/div/div[3]/button").click()
            self.dr.find_element_by_css_selector(
                ReadElement.Portal_ele(self, "忘记密码确认按钮")).click()
        except:
            # 截图
            function.error_png(self, ' test_7_ForgetPassword')
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.Portal_ele(self, "忘记密码确认按钮")).text, "OK")
コード例 #5
0
 def test_4_conditions(self):
     '''点击terms&conditions链接'''
     try:
         self.dr.find_element_by_xpath(
             ReadElement.Portal_ele(self, "conditions链接")).click()
         # self.dr.find_element_by_partial_link_text(ReadElement.Portal_ele(self,"conditions链接")).click()
         time.sleep(2)
         all = self.dr.window_handles
         # 切换到conditions页面用dr.switch_to.window不要用dr.switch_to_window
         # self.dr.switch_to_window(all[-1])
         self.dr.switch_to.window(all[-1])
         print('terms&conditions链接title:' + self.dr.title)
         # 断言
         # self.assertEqual(
         #     self.dr.title, "ThingsMatrix - Terms & Conditions")
     except:
         # 截图
         function.error_png(self, 'test_8_conditions')
         self.assertEqual(self.dr.title,
                          "ThingsMatrix - Terms & Conditions")
コード例 #6
0
    def test_5_Privacy(self):
        '''点击Privacy链接'''
        try:
            self.dr.find_element_by_partial_link_text(
                ReadElement.Portal_ele(self, "Privacy链接")).click()
            # self.dr.find_element_by_partial_link_text(ReadElement.Portal_ele(self,"conditions链接")).click()
            time.sleep(2)
            all = self.dr.window_handles

            # 切换到conditions页面用dr.switch_to.window不要用dr.switch_to_window
            self.dr.switch_to.window(all[-1])
            print(self.dr.title)
            time.sleep(2)

            # 断言
            self.assertEqual(self.dr.title, "ThingsMatrix - Privacy Policy")
        except:
            # 截图
            function.error_png(self, 'test_9_Privacy')
            self.assertEqual(self.dr.title, "ThingsMatrix - Privacy Policy")