PythonRemoteServer 使用,原文翻译)

技术PythonRemoteServer 使用,原文翻译) PythonRemoteServer 使用(原文翻译)PythonRemoteServerhttps://github.com/robotfr

PythonRemoteServer使用(原文翻译)

PythonRemoteServer

https://github.com/robotframework/PythonRemoteServer

允许在不同于机器人框架本身运行的进程或机器上托管测试库。

安装

点安装robotremoteserver ||python安装程序。巴拉圭安装

配置

远程服务器被实现为一个类RobotRemoteServer,它在初始化时接受以下配置参数:

argumentdefaultexpandionlibrary

测试要承载的库实例或模块。强制参数。

宿主

'127.0.0.1'

倾听的地址。使用"0.0.0.0"来侦听所有可用的接口。

港口

8270

港口听。使用0自动选择自由端口。可以作为整数或字符串给出。默认端口8270由IANAfor注册,用于远程服务器使用。

端口文件

没有人

文件来写入使用的端口。无(默认)表示不写入此类文件。

允许_停止

"已弃用"

自1.1版以来已弃用。请改用使用允许_远程_ .

服务

真实的

如果是,自动启动服务器并等待它停止。如果是,可以使用调查方法启动服务器。1.1版新增。

允许远程停止

真实的

允许/不允许使用停止远程服务器关键字和停止远程服务器XML-RPC方法远程停止服务器。1.1版新增。

启动服务器

简单地通过创建服务器实例并将测试库实例或模块传递给它来启动

从robotremoteserver导入机器人远程服务器

从mylibrary导入我的图书馆

RobotRemoteServer(MyLibrary())

默认情况下,服务器侦听地址127.0.0.1 和端口8270

从robotremoteserver导入机器人远程服务器

来自示例库导入前夫;前妻;前男友;前女友

ampleLibrary
RobotRemoteServer(ExampleLibrary(), host='10.0.0.42', port=0,
port_file='/tmp/remote-port.txt')

  从版本 1.1 开始,服务器可以在不启动的情况下使用参数来初始化serve=False。然后可以通过serve显式调用其方法来启动服务器

from robotremoteserver import RobotRemoteServer
from examplelibrary import ExampleLibrary
server = RobotRemoteServer(ExampleLibrary(), host='10.0.0.42', port=0,
                           port_file='/tmp/remote-port.txt', serve=False)
server.serve()

在后台启动服务器

单独初始化和启动服务器的主要好处是可以更容易地在后台线程中启动服务器。在线程中启动的服务器的工作方式与在主线程中运行的服务器完全一样,只是不支持优雅地使用或 信号停止服务器Ctrl-C。因此,如果需要,用户必须单独注册信号处理程序。

import signal
import threading
from examplelibrary import ExampleLibrary   #  实例
from robotremoteserver import RobotRemoteServer
server = RobotRemoteServer(ExampleLibrary(), port=0, serve=False)
signal.signal(signal.SIGINT, lambda signum, frame: server.stop())
server_thread = threading.Thread(target=server.serve)
server_thread.start()
while server_thread.is_alive():
    server_thread.join(0.1)

获取远程服务器开启端口

  如果服务器使用默认端口8270或在配置服务器时明确给出其他端口,您显然知道连接服务器时使用哪个端口。使用 port 时0,服务器会自动选择一个空闲端口,但有多种方法可以找到实际端

  • 使用的地址和端口打印到启动服务器的控制台中。
  • 如果使用port_file参数,服务器将端口写入指定文件,其他工具可以轻松读取它。从远程服务器版本 1.1 开始,当服务器停止时,服务器会自动删除端口文件。
  • 从 1.1 版本开始,服务器具有activate无需启动即可调用以激活服务器的方法。此方法返回服务器绑定的端口,并通过下面讨论的属性将其设置为可用。
  • 启动或活动的服务器实例具有server_address包含地址和端口作为元组的属性。从版本 1.1 开始,还有一个server_port属性只包含作为整数的端口。

停止远程服务器

  方法

  • 点击Ctrl-C运行服务器的控制台。如果服务器在后台线程上启动,则不自动支持。
  • 发送的过程SIGINTSIGTERMSIGHUP信号。如果服务器在后台线程上启动,则不适用于 Windows 并且不受支持。
  • 使用Stop Remote Server关键字。可以allow_remote_stop=False在初始化服务器时使用禁用。
  • stop_remote_server在 XML-RPC 接口中使用函数。可以使用allow_remote_stop=False初始化参数禁用。
  • 运行python -m robotremoteserver stop [uri]它采用上述stop_remote_server内部XML-RPC功能。可以使用allow_remote_stop=False初始化参数禁用。
  • 使用模块stop_remote_server提供的功能robotremoteserver与测试服务器运行时类似。在stop_remote_server内部使用XML-RPC 功能,可以通过allow_remote_stop=False初始化参数禁用。
  • 调用stop正在运行的服务器实例的方法。在后台运行服务器时主要有用。

测试远程服务器是否运行

$ python -m 机器人远程服务器测试
运行在 http://127.0.0.1:8270 的远程服务器。
$ python -m 机器人远程服务器测试 http://10.0.0.42:57347
没有在 http://10.0.0.42:57347 运行的远程服务器。

从版本 1.1 开始,该robotremoteserver模块包含test_remote_server可以以编程方式使用的功能

robotremoteserver模块还可用于通过stop在命令行上使用参数或以stop_remote_server编程方式使用该函数来停止远程服务器。测试和停止也适用于其他 Robot Framework 远程服务器实现

from robotremoteserver import test_remote_server
if test_remote_server('http://localhost:8270'):
    print('Remote server running!')

列出远程服务器关键字和查看文档

使用内置的Libdoc工具,您可以列出服务器上可用的关键字

$ python -m robot.libdoc Remote::http://127.0.0.1:8270 list
Count Items In Directory
Stop Remote Server
Strings Should Be Equal

也可以使用参数在命令行上显示文档show。可以通过提供输出文件的名称来创建 HTML 文档:

$ python -m robot.libdoc Remote::http://127.0.0.1:8270 MyLibrary.html
/path/to/MyLibrary.html

Example

#!/usr/bin/env python
from __future__ import print_function
import os
import sys
from robotremoteserver import RobotRemoteServer
try:
    basestring
except NameError:   # Python 3
    basestring = str
class ExampleLibrary(object):
    """Example library to be used with Robot Framework's remote server.
    This documentation is visible in docs generated by `Libdoc`.
    """
    def count_items_in_directory(self, path):
        """Returns the number of items in the directory specified by `path`."""
        items = [i for i in os.listdir(path) if not i.startswith('.')]
        return len(items)
    def strings_should_be_equal(self, str1, str2):
        print("Comparing '%s' to '%s'." % (str1, str2))
        if not (isinstance(str1, basestring) and isinstance(str2, basestring)):
            raise AssertionError("Given strings are not strings.")
        if str1 != str2:
            raise AssertionError("Given strings are not equal.")
if __name__ == '__main__':
    RobotRemoteServer(ExampleLibrary(), *sys.argv[1:])

启动

D:\Document\py\workspace\PythonRemoteServer-master\examplepython examplelibrary.py
Robot Framework remote server at 127.0.0.1:8270 started.
C:\Users\Administratorpython -m robot.libdoc Remote::http://127.0.0.1:8270 MyLi
brary.html
C:\Users\Administrator\MyLibrary.html
C:\Users\Administratorpython -m robot.libdoc Remote::http://127.0.0.1:8270 list
Count Items In Directory
Stop Remote Server
Strings Should Be Equal

test.robot

*** Settings ***
Library       Remote    http://${ADDRESS}:${PORT}
*** Variables ***
${ADDRESS}    127.0.0.1
${PORT}       8270
*** Test Cases ***
Count Items in Directory
    ${items1} =    Count Items In Directory    ${CURDIR}
    ${items2} =    Count Items In Directory    ${TEMPDIR}
    Log    ${items1} items in '${CURDIR}' and ${items2} items in '${TEMPDIR}'
Failing Example
    Strings Should Be Equal    Hello    Hello
    Strings Should Be Equal    not      equal

测试结果

Starting test: Tests.Count Items in Directory
20211110 11:00:54.938 :  INFO : ${items1} = 3
20211110 11:00:54.952 :  INFO : ${items2} = 4580
20211110 11:00:54.953 :  INFO : 3 items in 'D:\Document\py\workspace\RtfDistributedSys\workspace\Mdoule\RobotServer' and 4580 items in 'C:\Users\ADMINI~1\AppData\Local\Temp'
Ending test:   Tests.Count Items in Directory
Starting test: Tests.Failing Example
20211110 11:00:54.958 :  INFO : Comparing 'Hello' to 'Hello'.
20211110 11:00:54.961 :  INFO : Comparing 'equal' to 'equal'.
Ending test:   Tests.Failing Example

  

  • 使用的地址和端口打印到启动服务器的控制台中。
  • 如果使用port_file参数,服务器将端口写入指定文件,其他工具可以轻松读取它。从远程服务器版本 1.1 开始,当服务器停止时,服务器会自动删除端口文件。
  • 从 1.1 版本开始,服务器具有activate无需启动即可调用以激活服务器的方法。此方法返回服务器绑定的端口,并通过下面讨论的属性将其设置为可用。
  • 启动或活动的服务器实例具有server_address包含地址和端口作为元组的属性。从版本 1.1 开始,还有一个server_port属性只包含作为整数的端口。

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/79560.html

(0)

相关推荐

  • JMX在Tomcat的应用是怎样的

    技术JMX在Tomcat的应用是怎样的本篇文章给大家分享的是有关JMX在Tomcat的应用是怎样的,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。我们来详细说

    攻略 2021年12月9日
  • 哈尼族的传统节日风俗,哈尼族有哪些节日和风俗习惯

    技术哈尼族的传统节日风俗,哈尼族有哪些节日和风俗习惯居住习俗:哈尼族多居住在半山腰,依山势建立村寨。2.服装习俗:哈尼族一般用自己染织的藏青色土布做衣服。男人多穿对襟上衣和长裤,用黑布或白布裹头。妇女多穿右襟无领上衣,下

    生活 2021年10月21日
  • ceph块存储场景

    技术ceph块存储场景 ceph块存储场景1、创建rbd使用的存储池。admin节点需要安装ceph才能使用该命令,如果没有,也可以切换到ceph-node1节点去操作。[cephfsd@ceph-ad

    礼包 2021年11月29日
  • Vue 登录Id的传值+ 购物车的结算

    技术Vue 登录Id的传值+ 购物车的结算 Vue 登录Id的传值+ 购物车的结算一、登录Id的传值1、传值if (res.data.code !="") {this.$message({message

    礼包 2021年10月28日
  • 基于JAVA springboot+VUE前后端分离疫情防疫平台设计实现

    技术基于JAVA springboot+VUE前后端分离疫情防疫平台设计实现 基于JAVA springboot+VUE前后端分离疫情防疫平台设计实现基于JAVA springboot+VUE前后端分离

    礼包 2021年10月27日
  • microsoft.netframework有病毒吗(microsoftnetframework有害处吗)

    技术Microsoft .NET Framework漏洞是怎么样的这篇文章给大家介绍Microsoft .NET Framework漏洞是怎么样的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。0x0

    攻略 2021年12月21日