Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Robotframework将从python类传递的变量视为';无';_Python_Robotframework - Fatal编程技术网

Robotframework将从python类传递的变量视为';无';

Robotframework将从python类传递的变量视为';无';,python,robotframework,Python,Robotframework,我有一个python类Wiresharking.py from subprocess import Popen, CREATE_NEW_CONSOLE,PIPE,STDOUT import time import subprocess import datetime import os #import envSI class Wiresharking: """Wireshark Server subclass""" def __init__(self,**k

我有一个python类Wiresharking.py

from subprocess import Popen, CREATE_NEW_CONSOLE,PIPE,STDOUT
import time
import subprocess
import datetime
import os
#import envSI

class Wiresharking:

        """Wireshark Server subclass"""

        def __init__(self,**kwargs):

                self.filters=''
                self.window_ip = kwargs.get('ip')
                print type(self.window_ip)
                self.window_user= kwargs.get('username')
                self.window_password= kwargs.get('password')
                self.dest_path= kwargs.get('Target_path')
                self.interface= kwargs.get('interface')
                self.terminal='cmd'
                self.home=kwargs.get('Home_path')


        def test(self):
            print 'hi'
            return self.window_ip
我可以从另一个python文件(env.py)调用它,如下所示

SERVER_01 = Wiresharking(
        name='WIRESHARK_ENV91',
        ip='192.168.1.16',
        username=r'INTRA\pmmm',   #always prepend r , before giving your username and password
        password='jan@2018',
        prompt='$ ',
        autostart=False,
        unzip_capture=True,
        filter='',
        #interface=['ens2f0'],
        interface='Ethernet',
        Target_path=r'D:\Users\pankaj-m\Desktop\Test'
        )

print SERVER_01.test()
输出:

<type 'str'>
hi
192.168.1.16
检查。robot文件如下

*** Settings ***
Library    Wiresharking.py
*** Test Cases ***
Test
    check
*** Keywords ***
check
    ${abc} =    test
    log    ${abc}
我在这里得到的输出是“无”

16:13:37.279 INFO None 

谁能指出我在这里做错了什么。

您的
env.py
定义了一个名为
${SERVER\u 01}
的变量。但是,
Check.robot
从不使用该变量

Check.robot
导入
Wiresharking.py
而不传递任何参数。这导致其
self.window\u ip
None
,因此关键字返回
None

如果要查看
env.py
中的值,需要查看
${SERVER\u 01}
变量。例如:

log  ${SERVER_01.window_ip}

您的
env.py
定义了一个名为
${SERVER_01}
的变量。但是,
Check.robot
从不使用该变量

Check.robot
导入
Wiresharking.py
而不传递任何参数。这导致其
self.window\u ip
None
,因此关键字返回
None

如果要查看
env.py
中的值,需要查看
${SERVER\u 01}
变量。例如:

log  ${SERVER_01.window_ip}

这就是我能够通过**kwargs并能够解决错误的方法

我仍然在寻找一种更干净的方式通过**kwargs

*** Settings ***
Library    Wiresharking.py   ip=${SERVER_01.window_ip}    username=${SERVER_01.window_user}    password=${SERVER_01.window_password}    Target_path=${SERVER_01.dest_path}    interface=${SERVER_01.interface}    Home_path=${SERVER_01.home}  WITH NAME    Mylib

*** Variables ***
${window_ip }
#&{names} =  Create Dictionary   0=First Name    2=Email
*** Test Cases ***
Test
    check
*** Keywords ***
check
    ${abc} =    test
    log    ${abc}
输出

INFO 192.168.1.16

这就是我能够通过**kwargs并能够解决错误的方法

我仍然在寻找一种更干净的方式通过**kwargs

*** Settings ***
Library    Wiresharking.py   ip=${SERVER_01.window_ip}    username=${SERVER_01.window_user}    password=${SERVER_01.window_password}    Target_path=${SERVER_01.dest_path}    interface=${SERVER_01.interface}    Home_path=${SERVER_01.home}  WITH NAME    Mylib

*** Variables ***
${window_ip }
#&{names} =  Create Dictionary   0=First Name    2=Email
*** Test Cases ***
Test
    check
*** Keywords ***
check
    ${abc} =    test
    log    ${abc}
输出

INFO 192.168.1.16

我将如何将**kwargs值从机器人传递到init我已经发布了一个答案,如果你能指出通过**kwargs的任何其他方式,那将是非常棒的我将如何将**kwargs值从机器人传递到init我已经发布了一个答案,如果你能指出通过**kwargs的任何其他方式,那将是非常棒的