コード例 #1
0
 def refresh(self):
     """
     刷新页面
     :return:
     """
     self.driver.refresh()
     LOG.info("【刷新】")
コード例 #2
0
def assertEqual(first, second, msg=None):
    """Fail if the two objects are unequal as determined by the '=='
               operator.
            """
    """判断fist与second是否一致,msg类似备注,可以为空"""
    tt_check.assertEqual(first, second, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #3
0
 def forward(self):
     """
     Driver前进
     :return:
     """
     self.driver.forward()
     LOG.info("【前进】App前进")
コード例 #4
0
 def back(self):
     """
     Driver后退
     :return:
     """
     self.driver.back()
     LOG.info("【后退】App后退")
コード例 #5
0
ファイル: tt_selenium.py プロジェクト: boeai/mc
 def send_keys(self, locator, keywords):
     try:
         self.find_element(locator).send_keys(keywords)
         LOG.info("【输入】特征为{0}={1}的元素中".format(*locator) +
                  ",输入选择%s" % keywords)
     except Exception as msg:
         raise Exception("【输入】%s" % msg)
コード例 #6
0
 def test_getbaozhencar():
     """测试保真车获取接口@author:zhaoliuming"""
     api_tested = default_url + "/ajax/jsonp/getbaozhencar.ashx?cid=201&tid=1&callback=jQuery112402816550473892061_1564803591809"
     response = requests.get(api_tested)
     LOG.info("【访问】" + api_tested)
     status = response.status_code
     tt_check.assertEqual(status, 200, "请求是否成功:状态码%s" % status)
     tt_check.assertRegex(response.text, "成功", "返回是否包含成功")
コード例 #7
0
 def sleep(sec):
     """
     强制休眠
     :param sec: 秒
     :return:
     """
     time.sleep(sec)
     LOG.info("【等待】强制等待%s s" % sec)
コード例 #8
0
ファイル: tt_selenium.py プロジェクト: boeai/mc
    def set_window_size(self, wide, high):
        """
        Set browser window wide and high.

        Usage:
        driver.set_window_size(wide,high)
        """
        self.driver.set_window_size(wide, high)
        LOG.info("设置浏览器宽%s,高s%" % (wide, high))
コード例 #9
0
 def select_by_text(self, locator, text):
     """
     通过text选择下拉控件的选项
     :param locator:
     :param text:
     :return:
     """
     self.selector(locator).select_by_visible_text(text)
     LOG.info("【选择】特征为{0}={1}的下拉框".format(*locator) + ",选择%s" % text)
コード例 #10
0
 def touchaction_press(self, x: int, y: int):
     """
     按坐标点击
     :param x:横坐标,屏幕从左至右
     :param y:纵坐标,屏幕从上至下
     :return:
     """
     TouchAction(self.driver).press(x=x, y=y).release().perform()
     LOG.info("【点击】坐标(%d,%d)" % (x, y))
コード例 #11
0
 def close(self):
     """
     关闭当前窗口
     :return:
     """
     try:
         self.driver.close()
         LOG.info("【关闭】App")
     except ReferenceError:
         raise ReferenceError("未发现可关闭的App")
コード例 #12
0
 def select_by_value(self, locator, value):
     """
     通过value选择控件的选项
     :param locator:
     :param value:
     :return:
     """
     self.selector(locator).select_by_value(value)
     LOG.info("【选择】特征为{0}={1}的下拉框".format(*locator) +
              ",选择value为'%s'的选项" % value)
コード例 #13
0
 def select_by_index(self, locator, index):
     """
     通过index选择控件的选项
     :param locator:
     :param index:
     :return:
     """
     self.selector(locator).select_by_index(index)
     LOG.info("【选择】特征为{0}={1}的下拉框".format(*locator) + ",选择第%d个选项" %
              (index + 1))
コード例 #14
0
 def submit(self, locator):
     """
     提交某个元素表单
     :param locator:
     :return:
     """
     try:
         self.find_element(locator).submit()
         LOG.info("【提交】提交特征{0}={1}的表单".format(locator))
     except Exception as msg:
         raise Exception("【提交】%s" % msg)
コード例 #15
0
def assertTupleEqual(tuple1, tuple2, msg=None):
    """A tuple-specific equality assertion.

     Args:
         tuple1: The first tuple to compare.
         tuple2: The second tuple to compare.
         msg: Optional message to use on failure instead of a list of
                 differences.
     """
    tt_check.assertTupleEqual(tuple1, tuple2, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #16
0
def assertListEqual(list1, list2, msg=None):
    """A list-specific equality assertion.

    Args:
        list1: The first list to compare.
        list2: The second list to compare.
        msg: Optional message to use on failure instead of a list of
                differences.
    判断列表list1和列表list2是否相等
    """
    tt_check.assertListEqual(list1, list2, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #17
0
def assertSetEqual(set1, set2, msg=None):
    """A set-specific equality assertion.

    Args:
        set1: The first set to compare.
        set2: The second set to compare.
        msg: Optional message to use on failure instead of a list of
                differences.

    assertSetEqual uses ducktyping to support different types of sets, and
    is optimized for sets specifically (parameters must support a
    difference method).
    """
    tt_check.assertSetEqual(set1, set2, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #18
0
    def __init__(self, appium_service, desired_caps):
        """
        Run class initialization method, the default is proper
        to drive the Firefox browser,. Of course, you can also
        pass parameter for other browser, such as Chrome browser for the "Chrome",
        the Internet Explorer browser for "internet explorer" or "ie".
        """

        try:
            self.driver = webdriver.Remote(appium_service, desired_caps)
            self.driver.implicitly_wait(30)
            LOG.info("【打开】手机:%s,App:%s" %
                     (desired_caps['deviceName'], desired_caps['appPackage']))
        except Exception as msg:
            raise NameError("链接手机App失败!" + msg)
コード例 #19
0
def assertNotAlmostEqual(first, second, places=None, msg=None, delta=None):
    """Fail if the two objects are equal as determined by their
       difference rounded to the given number of decimal places
       (default 7) and comparing to zero, or by comparing that the
       difference between the two objects is less than the given delta.

       Note that decimal places (from zero) are usually not the same
       as significant digits (measured from the most significant digit).

       Objects that are equal automatically fail.
    """
    """同上,但判断相反
       注,delta与places不能同时存在,否则抛出异常"""
    tt_check.assertNotAlmostEqual(first, second, places, msg, delta)
    LOG.info("【检查】%s!" % msg)
コード例 #20
0
def assertSequenceEqual(seq1, seq2, msg=None, seq_type=None):
    """An equality assertion for ordered sequences (like lists and tuples).

    For the purposes of this function, a valid ordered sequence type is one
    which can be indexed, has a length, and has an equality operator.

    Args:
        seq1: The first sequence to compare.
        seq2: The second sequence to compare.
        seq_type: The expected datatype of the sequences, or None if no
                datatype should be enforced.
        msg: Optional message to use on failure instead of a list of
                differences.
    """
    tt_check.assertSequenceEqual(seq1, seq2, msg, seq_type)
    LOG.info("【检查】%s!" % msg)
コード例 #21
0
def assertCountEqual(first, second, msg=None):
    """An unordered sequence comparison asserting that the same elements,
    regardless of order.  If the same element occurs more than once,
    it verifies that the elements occur the same number of times.

        self.assertEqual(Counter(list(first)),
                         Counter(list(second)))

     Example:
        - [0, 1, 1] and [1, 0, 1] compare equal.
        - [0, 0, 1] and [0, 1] compare unequal.

    """
    """a和b具有相同数字的相同元素,无论它们的顺序如何"""
    tt_check.assertCountEqual(first, second, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #22
0
    def test_sellcar_submitclue(self):
        """测试提交卖车线索是否成功@author:zhangyanli"""
        test_login.Login.login(self)
        sleep(3)
        self.driver.find_element(SellCar_Locator.SELL_CAR_TAB).click()
        sleep(2)
        self.driver.find_element(SellCar_Locator.SELL_CAR_CITY).click()
        sleep(2)
        self.driver.find_element(SellCar_Locator.SELL_CAR_CHOOSE_CITY).click()
        sleep(2)
        #ele = self.driver.find_element(SellCar_Locator.SELL_CAR_BUTTON)
        #self.driver.execute_script("arguments[0].scrollIntoView();", ele)
        #self.driver.execute_script("arguments[0].click();", ele)
        #sleep(1)

        self.driver.execute_script("window.scrollTo(0, 500)")
        self.driver.find_element(SellCar_Locator.SELL_CAR_BUTTON).click()
        sleep(2)
        LOG.info("【免费看车提交成功】")
コード例 #23
0
def assertAlmostEqual(first, second, places=None, msg=None, delta=None):
    """Fail if the two objects are unequal as determined by their
               difference rounded to the given number of decimal places
               (default 7) and comparing to zero, or by comparing that the
               difference between the two objects is more than the given
               delta.

               Note that decimal places (from zero) are usually not the same
               as significant digits (measured from the most significant digit).

               If the two objects compare equal then they will automatically
               compare almost equal.
            """
    """注:places与delta不能同时存在,否则出异常,
       若a==b,则直接输入正确,不判断下面的过程
       若delta有数,places为空,判断a与b的差的绝对值是否<=delta,满足则正确,否则错误
       若delta为空,places有数,判断b与a的差的绝对值,取小数places位,等于0则正确,否则错误
       若delta为空,places为空,默认赋值places=7"""
    tt_check.assertAlmostEqual(first, second, places, msg, delta)
    LOG.info("【检查】%s!" % msg)
コード例 #24
0
ファイル: tt_selenium.py プロジェクト: boeai/mc
    def __init__(self,
                 browser='chrome',
                 btype='pc',
                 is_headless=False,
                 mobile_options=None):
        """
        Run class initialization method, the default is proper
        to drive the Firefox browser,. Of course, you can also
        pass parameter for other browser, such as Chrome browser for the "Chrome",
        the Internet Explorer browser for "internet explorer" or "ie".
        """
        if browser == "firefox":
            driver = webdriver.Firefox()

        elif browser == "ie":
            driver = webdriver.Ie()

        elif browser == "chrome":
            options = webdriver.ChromeOptions()
            # 是否开启静默
            if is_headless:
                options.add_argument('--headless')
                options.add_argument('--disable-gpu')

            if btype == "pc":
                driver = webdriver.Chrome(chrome_options=options)

            elif btype == "m":
                options.add_argument(mobile_options)
                driver = webdriver.Chrome(chrome_options=options)
            else:
                raise NameError("选择Chrome时,默认为pc,测试M站需要指定type='m'。")

        try:
            self.driver = driver
            LOG.info("【打开】%s" % browser)
        except Exception as msg:
            raise NameError("泰坦仅支持Firefox、IE和Chrome浏览器!" + msg)
コード例 #25
0
def assertIsNone(obj, msg=None):
    """Same as self.assertTrue(obj is None), with a nicer default message."""
    """判断obj=None 成立则通过,否则失败"""
    tt_check.assertIsNone(obj, msg)
    LOG.info("【检查】%s,Pass!" % msg)
コード例 #26
0
def assertNotIn(member, container, msg=None):
    """Just like self.assertTrue(a not in b), but with a nicer default message."""
    """判断a in b是否成立,不成立则True 否则 False"""
    tt_check.assertNotIn(member, container, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #27
0
def assertTrue(expr, msg=None):  #判断a是否为True
    """Check that the expression is true."""
    tt_check.assertTrue(expr, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #28
0
def assertNotIsInstance(obj, cls, msg=None):
    """Included for symmetry with assertIsInstance."""
    """判断a的数据类型是否为b,isinstance(a,b) 成立则通过,否则失败"""
    tt_check.assertNotIsInstance(obj, cls, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #29
0
def assertIsInstance(obj, cls, msg=None):
    """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
            default message."""
    tt_check.assertIsInstance(obj, cls, msg)
    LOG.info("【检查】%s!" % msg)
コード例 #30
0
def assertIsNotNone(obj, msg=None):
    """Included for symmetry with assertIsNone."""
    """判断obj=None 成立则失败,否则通过"""
    tt_check.assertIsNotNone(obj, msg)
    LOG.info("【检查】%s!" % msg)