2017-12-12 4 views
-2

ロボットフレームワークでどのようにクラスのオブジェクトを作成し、対応するクラスのメソッドを呼び出すのですか?これがコードスニペットです。ロボットフレームワークでどのようにクラスのオブジェクトを作成し、対応するクラスのメソッドを呼び出すのですか?

*** Settings *** 
Documentation  A resource file with reusable keywords and variables. 
...    Use keywords in this file in testcases directory. 
Library   /home/kirti/src/Helper/utilities.py 
Library   /home/kirti/src/Helper/config_parser.py 
#Library   /home/kirti/qa/src/executor/cleanup.CleanUp 
Library   /home/kirti/qa/src/executor/cleanup.py 

*** Variables *** 
${RESULT}   0 

*** Keywords *** 
Read Json Config Values 
    Log To Console  "Setting up the config values globally" 
    config_parser.Json Config Parser 
    Import Variables /home/kirti/src/Helper/variables.py 
    Log Variables INFO 

Check Machines Reachability 
utilities.Check All Machines Status 

Check SNMP Counter 
    utilities.Get Snmp 192.178.1.2 PPSessionCount 

Call Clean Up 
    #${cleanupobj}=  cleanup.create cleanup 
    #${name}=  ${cleanupobj.cc()} 
    Import Library  /home/kirti/src/executor/cleanup.py 
    ${cmp}= Get library instance CleanUp 
    Log To Console  ${cmp}.__class__.__name__ 
    #${name}= Call method ${cmp} Create cleanup 
    ${name}= Call method ${cmp} cc 
    #${name}= Call method ${cleanupobj} env cleanup 
    #Log To Console  "${name}" 
    #Log Variables INFO 
    utilities.Check All Machines Status 
+0

にこれらの方法を使用できるように、クラスサンプル

サンプルクラスはINITを有し有するdemo.pyの例を取るgetting_path()でき[so]へようこそ。質問には[mcve]があるのが一般的です。あなたのコード例は、悲しいことに、これらの基準を満たしていないため(Pythonコードがない)、最小限ではなく(コードコメントや他のコード)、実際の応答を提供していません。 –

答えて

0

これは、望ましい結果を得る方法です。

メソッド

class Sample(object): 
    def __init__(self,path,device): 
      self.device=device 
      self.path = path 

    def getting_path(self): 
      return self.path 

Robotfile

*** Settings *** 
#in the Library section you reference python class in below format 
# (file.class_name) so file is demo.py and class is Sample 

Library  demo.Sample ${path} ${device} WITH NAME obj 

#path and device are two arguments required by __init__,'obj' will be used to 
#access the methods in python class 

Library Collections 

*** Variables *** 
${path} c: 
${device} samsung 


*** Test Cases *** 
Test 
    Test_python_class 

*** Keywords *** 
Test_python_class 

    #with obj you now call the method of python file 
    ${result} = obj.getting_path 

    #if method need any argument , this can be passed like 
    #${result} = obj.getting_path ${arg1} ${arg2} 
    log to console ${result} 
関連する問題