繁体   English   中英

Robot Framework 无法识别某些类关键字

[英]Robot Framework not recognizing some class keywords

我正在创建一个包含三个不同类的 RobotFramework 库。 我可以使用 first class 关键字,但是我不能使用剩余的两个 classes 关键字。 根据 RF 文档,我尝试按照 LibraryName.className 使用导入,并且我还将 python 路径设置为我的个人库文件夹。 但是,在运行测试时仅识别第一类关键字。 我试图将我的第一个类的名称更改为与我的 lib 文件不同的名称,并分别导入每个类,但这对三个类的关键字不起作用。

这是我的 Lib 代码:

from robotpageobjects import Page, robot_alias
from robot.utils import asserts


class HomePage(Page):
    """ Models WeekendDesk home page at:
        HOST:weekendesk.fr/"""

    name="Home"
    # This is Then Keyword for Weekendesk Home Page.

    # This page is found at baseurl"
    uri = ""

    # inheritable dictionary mapping human-readable names
    # to Selenium2Library locators. You can then pass in the
    # keys to Selenium2Library actions instead of the locator
    # strings.

    selectors = {
        "destination": "id=concatField",
        "search button": "id=searchButton",
        "arrival date": "id=spArrival",
        "departure date": "id=spDeparture",

    }

    # Use robot_alias and the "__name__" token to customize
    # where to insert the optional page object name
    # when calling this keyword. Without the "__name__"
    # token this method would map to either "Type In Search Box",
    # or "Type In Search Box WDHomePage". Using "__name__" we can call
    # "Type in Home Search Box  foo".
    @robot_alias("type_in__name__search_box")
    def type_in_search_box(self, txt):
        self.input_text("destination", txt)

        # We always return something from a page object,
        # even if it's the same page object instance we are
        # currently on.
        return self

    @robot_alias("type_in__name__arrival_box")
    def type_in_arrival_box(self, txt):
        self.input_text("arrival date", txt)

        # We always return something from a page object,
        # even if it's the same page object instance we are
        # currently on.
        return self

    @robot_alias("type_in__name__departure_box")
    def type_in_departure_box(self, txt):
        self.input_text("departure date", txt)

        # We always return something from a page object,
        # even if it's the same page object instance we are
        # currently on.
        return self

    @robot_alias("click__name__search_button")
    def click_search_button(self):
        self.click_link("search button")
        return SerpPage()

    @robot_alias("search_weekends_for")
    def search_for(self, concatField,spArrival,spDeparture):
        self.type_in_search_box(concatField)
        self.type_in_arrival_box(spArrival)
        self.type_in_departure_box(spDeparture)
        return self.click_search_button()


class SerpPage(Page):

    """Models a Serp search result page. For example:
    http://www.weekendesk.fr/sejour/DTE6_070815RGN1_iPLC2_3iNGH1_5VRS1_9  /weekend-en-PACA """
    # The URI for the SERP page does not have a template to follow

    uri = ""
    Name= "Serp"

    # This is a "selector template". We are parameterizing the
    # nth result in this xpath. We call this from click_result, below.
    selectors = {
        "nth result link": "div.searchResult:nth-child(1) > div:nth-child(1) > h2:nth-child(1) > a:nth-child(1)"

    }

    @robot_alias("click_result_on__name__")
    def click_result(self, i):

        # For selector templates, we need to resolve the selector to the
        # locator first, before finding or acting on the element.
        locator = self.resolve_selector("nth result link", n=int(i))
        self.click_link(locator)
        return ProductPage()

class ProductPage(Page):

    uri = ""
    Name="Product"

    @robot_alias("__name__body_should_contain")
    def body_should_contain(self, str, ignore_case=True):
        ref_str = str.lower() if ignore_case else str
        ref_str = ref_str.encode("utf-8")
        body_txt = self.get_text("css=body").encode("utf-8").lower()
        asserts.assert_true(ref_str in body_txt, "body text does not contain %s" %ref_str)
        return self

我的 Lib 文件名是 HomePage.py

谢谢

您要求做的事情应该是可能的,但是,如果没有看到您的机器人测试套件,就不清楚您实际在做什么。 例如,如果您的库文件在 PYTHONPATH 上,您可以单独导入这些类。 例如,如果这是您的库文件,我将其命名为LibTest.py

from robot.api import logger

class LibTest:
    def libtest_1(self):
        logger.warn("In LibTest")

class OtherTest:
    def othertest_1(self):
        logger.warn("In OtherTest")

class OneMoreTest:
    def onemoretest_1(self):
        logger.warn("In OneMoreTest")

然后在您的测试套件中,您可以单独加载类:

*** Settings ***
Library           LibTest.LibTest
Library           LibTest.OtherTest
Library           LibTest.OneMoreTest
 
*** Test Cases ***
sometest
    Log    Test Start
    libtest_1
    othertest_1
    onemoretest_1

这个例子适用于我的环境:Python 2.7.6 with Robot Framework 2.8.7。 这是我输出的控制台:

20150831 12:48:49.449:信息:测试开始

20150831 12:48:49.450:警告:在 LibTest 中

20150831 12:48:49.450:警告:在其他测试中

20150831 12:48:49.451:警告:在 OneMoreTest 中

不过,我认为 Robot 确实是在鼓励您将库类保存在单独的文件中 - 因为它更容易处理,即您不需要将它们放在 PYTHONPATH 中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM