iT邦幫忙

0

如何在robot framework操作2個android裝置,在不重開app情況下回頭操作前一個device

各位大神好:
小弟目前在寫robot framework,想要操作2個android裝置(不用同時沒關係),前置作業和操作步驟如下:

Pre-condition:
1.先用Android Studio創建2台android模擬器(假設一台叫"device1",另一台叫"device1")
2.在device1和device2都安裝一個app(貴公司自己建的app)

Steps:
1.用"Open Application"先打開device1的app
2.再Login app
3.接著再用"Open Application"打開device2的app
4.再Login app

問題來了,這時候我想繼續回頭操作device1的app,發現找不到相關的Keyword可以繼續操作device1的app(在device1不重新開啟一個新app的情況下),如果繼續寫相關case,都會一直在device2下操作,如果用"Open Application",就會關閉原本已經在device1登入的app,請問各位大大是否有解?

1 個回答

1
dragonH
iT邦超人 6 級 ‧ 2019-08-21 20:19:33

沒用過這東西

不過應該有辦法將測試分別用變數儲存吧

你該不會是直接覆蓋掉前一個之類的吧?

多裝置測試參考


無聊玩的 /images/emoticon/emoticon01.gif

多個 browser 測試

img

index.robot

*** Settings ***
Documentation     A test suite with a single test for valid login.
...
...               This test has a workflow that is created using keywords in
...               the imported resource file.
Resource          resource.robot

*** Test Cases ***
Valid Login
    Open Browser1 To Login Page
    Open Browser2 To Login Page
    Input Username    demo    Web1
    Input Username    browser2    Web2
    Input Password    mode    Web1
    Input Password    mode    Web2
    Submit Credentials    Web1
    Submit Credentials    Web2
    Welcome Page Should Be Open    Web1
    Login Should Have Failed    Web2
    Close Test Browser    Web1
    Close Test Browser    Web2

resource.robot

*** Settings ***
Documentation     A resource file with reusable keywords and variables.
...
...               The system specific keywords created here form our own
...               domain specific language. They utilize keywords provided
...               by the imported SeleniumLibrary.
Library           SeleniumLibrary

*** Variables ***
${SERVER}         localhost:7272
${BROWSER}        Firefox
${DELAY}          0.25
${VALID USER}     demo
${VALID PASSWORD}    mode
${LOGIN URL}      http://${SERVER}/
${WELCOME URL}    http://${SERVER}/welcome.html
${ERROR URL}      http://${SERVER}/error.html
  

*** Keywords ***
Open Browser1 To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}    alias=Web1
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open
    
Open Browser2 To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}    alias=Web2
    Set Window Position    950     10
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open

    
    
Login Page Should Be Open
    Title Should Be    Login Page

Go To Login Page
    Go To    ${LOGIN URL}
    Login Page Should Be Open

Input Username
    [Arguments]    ${username}    ${web}
    switch browser    ${web}
    Input Text    username_field    ${username}

Input Password
    [Arguments]    ${password}    ${web}
    switch browser    ${web}
    Input Text    password_field    ${password}

Submit Credentials
    [Arguments]    ${web}
    switch browser    ${web}
    Click Button    login_button

Welcome Page Should Be Open
    [Arguments]    ${web}
    switch browser    ${web}
    Location Should Be    ${WELCOME URL}
    Title Should Be    Welcome Page

Close Test Browser
    [Arguments]    ${web}
    switch browser    ${web}
    Close Browser

Login Should Have Failed
    [Arguments]    ${web}
    switch browser    ${web}
    Location Should Be    ${ERROR URL}
    Title Should Be    Error Page
hbl030201 iT邦新手 5 級 ‧ 2019-08-22 16:30:02 檢舉

Dear dragonH:
感謝你的回覆!我照你的方式修改確實可以解決我的問題,後來我發現原因出在我沒有加"alias"去區分不同app,以及可以用"Switch Application"去切換其他app操作,感謝你的解答^^

dragonH iT邦超人 6 級 ‧ 2019-08-22 16:36:07 檢舉

/images/emoticon/emoticon12.gif

我要發表回答

立即登入回答