簡體   English   中英

在RED機器人框架Eclipse編輯器中指定用戶定義的Java庫時出錯

[英]It errors when specifying the user defined java library into RED robot framework eclipse editor

我的要求是在使用RED Eclipse編輯器的機器人框架中使用用戶定義的Java庫。 嘗試在機械手框架中指定庫時,系統錯誤,因為沒有可用的庫(庫名稱以紅色下划線顯示)。 請更正我的錯誤。 我已按照以下步驟操作,

  1. 使用RED編輯器更新了Eclipse(Eclipse Neon(v 4.6),RED-Robot Editor v0.7.5)
  2. 與Project一樣在相同的Eclipse中創建了一個類文件。 (程序包名稱:org.robot.KCCKeywords和類名稱:LogonToKCC)
  3. 將類文件轉換為類型“ .JAR”,並將其存儲在jython文件夾中(C:\\ jython2.7.0 \\ Lib \\ site-packages \\ KCCLibraries)
  4. 使用launch4j-3.8-win32將RED與Maven插件集成(使用https://github.com/nokia/RED/blob/9d62dccce18ee7f3051162d05bf3d027e33dccef/red_help/user_guide/maven.html.md
  5. 將RED與Robot框架和Jython集成在一起。 (使用https://github.com/nokia/RED/blob/9d62dccce18ee7f3051162d05bf3d027e33dccef/red_help/user_guide/maven.html.md
  6. 為以下罐子更新了CLASS PATH,

    a)jython.jar b)robotframework-3.0.2.jar c)myOwnJavaLibrary.jar(我在步驟3中創建的jar)d)jdk和jre路徑

  7. 還在red.xml中驗證了相同的類路徑。
  8. 創建了RED項目並開始初始化關鍵字,如下所示:

    a)庫Selenium2Library

    b)庫org.robot.KCCKeywords.LogonToKCC

這是系統無法讀取我自己的庫的地方。 我還參考了以下博客,並相應地調整了步驟。 但是沒有幫助我。 提到多個博客和堆棧也使我感到困惑。 終於我來了

使用以代碼為中心的博客: 機器人框架教程-以Java編寫關鍵字庫為基礎,並為RED代替RIDE提供了一些特定步驟。 本演練將使您可以設置Jython,使用Java創建一個簡單的庫並從Robot腳本運行它。

在Eclipse中安裝Eclipse(NEON)和RED Feature之后,在Eclipse中創建一個新的Java項目。 完成后,繼續創建具有以下內容的新Java類。

package org.robot.sample.keywords;

import java.util.Stack;

/**
 * This is an example for a Keyword Library for the Robot Framework.
 * @author thomas.jaspers
 */
public class SampleKeywordLibrary {

    /** This means the same instance of this class is used throughout
     *  the lifecycle of a Robot Framework test execution.
     */
    public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";    

    //</editor-fold>
    /** The Functionality to be tested */
    private Stack<String> testStack;

    /**
     * Keyword-method to create an empty stack.
     */
    public void createAnEmptyStack() {
        testStack = new Stack<String>();
    }


    /**
     * Keyword-method to add an element to the stack.
     * @param element The element
     */
    public void addAnElement(String element) {
        testStack.push(element);
    }

    /**
     * Keyword-method to remove the last element from the stack.
     */
    public void removeLastElement() {
        testStack.pop();
    }

    /**
     * Keyword-method to search for an element position.
     * @param element The element
     * @param pos The expected position
     */
    public void elementShouldBeAtPosition(String element, int pos) 
            throws Exception {
        if (testStack.search(element) != pos) {
            throw new Exception("Wrong position: " + testStack.search(element));
        }
    }

    /**
     * Keyword-method to check the last element in the stack.
     * @param result Expected resulting element
     */
    public void theLastElementShouldBe(String result) throws Exception {
        String element = testStack.pop();
        if (!result.equals(element)) {
            throw new Exception("Wrong element: " + element);
        }
    }
}

請確保使用Windows Installer安裝了Jython。 在我的示例中,Jython安裝在c:\\ Jython中。 與常規Python解釋器機器人框架一樣,仍然需要安裝。 假設您的計算機可以訪問Internet,請在命令行中轉到c:\\Jython\\bin\\並運行命令pip install robotframework 這將在Jython環境中安裝Robot Framework。

現在,在Eclipse中創建一個新的Robot Framework項目。 請確保您具有“ Window > Perspective > Open Perspective > Robot或“ Other > Robot

在此處輸入圖片說明

在項目中,默認的Robot Framework是基於Python的機器人框架,我們需要配置Jython解釋器。 在Eclipse中,轉到“ Window > Preferences ,然后從樹菜單中選擇“ Robot Framework > Installed Frameworks ”。 單擊Add然后指向c:\\Jython\\bin\\ 單擊確定。

在此處輸入圖片說明

從機器人項目中打開Red.XML,然后轉到general標簽。 這是設置項目解釋器的地方。 如果將其設置為Python(如下面的示例),則單擊use local settings for this project然后檢查Jython解釋器。 將設置保存到文件(CTRL-S)。

在此處輸入圖片說明

使用Robot Framework項目設置,是時候將Java類導出到Jar文件了。 右鍵單擊類文件,然后單擊export 然后選擇JAR file ,然后點擊next 單擊Browse並設置JAR文件的位置和文件名。 在這種情況下,我選擇了ExampleLibrary.jar和我的機器人項目的文件夾。 Finish以完成導出。

返回Red.XML並單擊“ Referenced Libraries然后單擊“ Add Java library ,選擇導出的Jar文件(ExampleLibrary.jar),然后按“確定”。 這將繼續加載jar並從Jar文件中讀取關鍵字。 保存文件(CTRL-S)。 這將導致以下參考。

在此處輸入圖片說明

現在該創建一個Robot文件並使用該庫了。 在引用的博客中,給出了使用Java函數/關鍵字的以下示例腳本。

*** Settings ***
Library    org.robot.sample.keywords.SampleKeywordLibrary

*** Test Cases ***
ExampleJava
    Create An Empty Stack
    Add An Element    Java
    Add An Element    C++
    Remove Last Element
    The Last Element Should Be    Java

在已經加載的庫中,不會出現紅線,否則請右鍵單擊該庫,然后單擊quick-fix並自動發現該庫。

然后使用常規的Eclipse / RED Run菜單運行腳本。 然后,它將成功運行腳本並輸出以下內容:

Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Eclipse\Workspace\ExamplJava\ExampleLibrary.jar -m robot.run --listener C:\Users\User\AppData\Local\Temp\RobotTempDir8926065561484828569\TestRunnerAgent.py:57292:False -s ExamplJava.ExampleJava C:\Eclipse\Workspace\ExamplJava
Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_60)
==============================================================================
ExamplJava                                                                    
==============================================================================
ExamplJava.ExampleJava                                                        
==============================================================================
ExampleJava                                                           | PASS |
------------------------------------------------------------------------------
ExamplJava.ExampleJava                                                | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
ExamplJava                                                            | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  C:\Eclipse\Workspace\ExamplJava\output.xml
Log:     C:\Eclipse\Workspace\ExamplJava\log.html
Report:  C:\Eclipse\Workspace\ExamplJava\report.html

我終於按照以下內容進行了機器人框架的偉大旅程。

1   Installed Java, Eclipse, RED Eclipse plugin.
   a) Java(JDK 1.8.0/JRE 1.8.0)
   b) Eclipse Neon (v 4.6)
   c) RED - Robot Eclipse Editor v0.7.5.2(Eclipse Plugin)
2   Downloaded and Installed Python 2.7.12 using windows. A folder created automatically after installation in C:\python27
3   "Installed Robot Framework using pip command in Command Prompt.
     Command:     C:\python27\scripts>pip install robotframework"
4   Downloaded and installed Jython 2.7.0 using windows. A folder created automatically after installation in C:\jython2.7.0
5   "Installed Robot Framework using pip command in Command Prompt.
     Command:     C:\jython2.7.0\bin>pip install robotframework"
6   "Installed Selenium2Library using pip command in Command Prompt.
     Command:     C:\jython2.7.0\bin>pip install robotframework-selenium2library"
7   "Set the below,
    a) Goto Window-Preferences-Robot Framework-Installed Framework
    b) Map Robot framework with Jython Interpreter
    I used c:\jython2.7.0\bin"
8   Created JavaProject and export it into a jar file. Right click on the class name, click on export-Java-Jarfile. Select the path name where the new jar file to be put including the new file name.jar. Click Ok.
9   Open RED.xml Click Add Java Library and select the newly created jar file.
10  "Set up this before proceeding with robot framework 
    goto Windows - Perspective - Open Perspective-Other-Robot"
11  Create a robot suite, import library selenium2library & user defined library, Write Test cases.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM