{"id":827,"date":"2023-03-03T22:39:50","date_gmt":"2023-03-03T14:39:50","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=827"},"modified":"2023-04-29T16:51:17","modified_gmt":"2023-04-29T08:51:17","slug":"robot-framework-customize-its-own-python-library","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/03\/robot-framework-customize-its-own-python-library\/","title":{"rendered":"Robot Framework \u81ea\u5b9a\u4e49\u81ea\u5df1\u7684Python\u5e93"},"content":{"rendered":"<p>\u5229\u7528Robot Framework\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u5f80\u5f80\u9700\u8981\u5f00\u53d1\u81ea\u5df1\u7684\u5173\u952e\u5b57\uff0c\u6709\u7684\u5173\u952e\u5b57\u9700\u8981\u901a\u8fc7\u81ea\u5df1\u7f16\u5199Python\u4ee3\u7801\u6765\u5b9e\u73b0\uff0c\u8fd9\u5c31\u9700\u8981\u81ea\u5df1\u5b9a\u4e49Python\u5e93\u3002<\/p>\n<p>1\u3001\u5728 Python\u9879\u76ee\u76ee\u5f55\u4e0b <code>New<\/code> -&gt; <code>Python Package<\/code>\uff0c\u65b0\u5efa\u540d\u4e3a <code>yezhou<\/code> \u7684\u5305<\/p>\n<p>2\u3001\u5728\u65b0\u5efa\u7684 yezhou \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2apython\u6587\u4ef6\uff0c\u5982\uff1a<code>myclass.py<\/code>\uff0c\u5185\u5bb9\u4e3a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\">class MyClass(object):\n\n    def __init__(self):\n        pass\n\n    def printMsg(self, msg):\n        print &quot;hello &quot; + msg<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2apython\u7c7b\uff0c\u5176\u4e2d\u9664\u6784\u9020\u65b9\u6cd5 <code>_init_<\/code> \u5916\uff0c\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a <code>printMsg<\/code>\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5176\u5b9e\u5c31\u662fRobot Framework\u4e2d\u7684\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728Robot Framework\u4e2d\u4f7f\u7528\u3002<\/p>\n<p>3\u3001\u7f16\u8f91 yezhou \u76ee\u5f55\u4e0b\u7684 <code>__init__.py<\/code> \u6587\u4ef6\uff08\u5982\u679c\u6ca1\u6709\u5219\u521b\u5efa\uff09\uff0c\u6587\u4ef6\u540d\u5fc5\u987b\u56fa\u5b9a\u8fd9\u6837\u3002\u8be5\u6587\u4ef6\u7684\u529f\u80fd\uff0c\u5c31\u662f\u5c06\u5173\u952e\u5b57\u7c7b\u66b4\u9732\u51fa\u6765\u3002<\/p>\n<pre><code class=\"language-python\">from myclass import MyClass\n\nclass yezhou(MyClass):\n    ROBOT_LIBRARY_SCOPE = &#039;GLOBAL&#039;\n    __version__ = &#039;0.1&#039;<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\u610f\uff1a<code>__init__.py<\/code> \u6587\u4ef6\u4e2d\uff0cclass yezhou(MyClass) \u7c7b\u540d\u79f0\u8981\u4e0e package \u5305\u540d\u79f0\u4e00\u81f4<\/p>\n<\/blockquote>\n<p>4\u3001\u914d\u7f6e PYTHONPATH<\/p>\n<p>\u6dfb\u52a0\u6216\u8bbe\u7f6e PYTHONPATH \u73af\u5883\u53d8\u91cf\uff0c\u5c06\u9879\u76ee\u76ee\u5f55\u914d\u7f6e\u5230 PYTHONPATH \u4e2d<\/p>\n<p>PYTHONPATH  E:\\Python-Project\\YeZhou<\/p>\n<p>5\u3001\u901a\u8fc7\u524d\u9762\u6b65\u9aa4\uff0c\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u81ea\u5b9a\u4e49\u7684Python\u5e93\u5c31\u521b\u5efa\u597d\u4e86\uff0c\u5728Robot Framework\u4e2d\u5373\u53ef\u5f15\u7528<\/p>\n<p>1\uff09\u9996\u5148\u5bfc\u5165 yezhou \u5e93<\/p>\n<p>2\uff09\u4f7f\u7528\u5173\u952e\u5b57printMsg\u3002\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u5728Robot Framework\u4e2d\u5f15\u7528\u65f6\uff0c\u65e2\u53ef\u4ee5\u5199\u6210 <code>printMsg<\/code>\uff0c\u4e5f\u53ef\u5199\u6210 <code>Print Msg<\/code> \u6216 <code>print msg<\/code>\u3002\u4e00\u822c\u4e60\u60ef\u7528\u7a7a\u683c\u628a\u5355\u8bcd\u5206\u5f00\u3002\u56e0\u4e3aRobot Framework\u5173\u952e\u5b57\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<pre><code class=\"language-python\">*** Settings ***\nLibrary           yezhou\n\n*** Test Cases ***\nsuccesssd\n    Print Msg    appblog.cn\n    print msg    appblog.cn\n    printMsg     appblog.cn<\/code><\/pre>\n<p>6\u3001\u589e\u52a0\u65b0\u7684\u5173\u952e\u5b57<\/p>\n<p>\u589e\u52a0\u65b0\u7684\u5173\u952e\u5b57\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u5728MyClass\u7c7b\u4e2d\u589e\u52a0\u65b0\u7684\u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528Robot Framework\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u5f80\u5f80\u9700\u8981\u5f00\u53d1\u81ea\u5df1\u7684\u5173\u952e\u5b57\uff0c\u6709\u7684\u5173\u952e\u5b57\u9700\u8981\u901a\u8fc7\u81ea\u5df1\u7f16\u5199Pytho [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[228],"tags":[],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-robot-framework"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}