testproject-io / robot-library

TestProject Library for Robot
Apache License 2.0
6 stars 8 forks source link

How to run tests on mobile devices and cloud browsers (e.g. Browserstack) via the robot-library? #18

Open af-mle opened 3 years ago

af-mle commented 3 years ago

How can the following kinds of test been run via the robot-library?

All those variations work fine via the OpenSDK.

Based on the example tests for the python-opensdk library utilizing Pytest, I was able to script tests for all the following variants of browser and (Android) app testing

To connect to the mobile devices via python-opensdk library the "remote" driver and appropriate capabilities can be used, see example code below.

desired_capabilities = {
        "appActivity": "io.testproject.demo.MainActivity",
        "appPackage": "io.testproject.demo",
        "udid": android_emulator_id,
        "browserName": "",
        "platformName": "Android",
    }

 driver = webdriver.Remote(desired_capabilities=desired_capabilities)

The robot-library seems to only provide the option to chose the "generic" driver in the function init_testproject_driver in the file TestProjectLibrary.py. Can thios be used to connect via the TP agent to mobile devices and cloud browsers?

Artem-Kuz commented 3 years ago

Hi, regarding running BrowserStack tests using the TestProject robot-framework, It is possible by providing the correct capabilities. Here is an example to how set up your BrowserStack test using the TestProject robot-framework:


*** Settings ***
Library         TestProjectLibrary
Library         String
Suite Setup     Init
Suite Teardown  Close

*** Test Cases ***
Set Session
    ${previous kw}=                 Register Keyword To Run On Failure      None
    set selenium implicit wait      30 seconds

Work On Actions
    Press Keys      //a[contains(text(), 'Actions')]
    ${buttons_count}=           Get Element Count   //div[@class='list-group']/button
    ${start}                    Set Variable        2
    FOR     ${i}   IN RANGE     ${start}            ${buttons_count}
            Click Button        (//div[@class='list-group']/button)[${i}]
            Run Keyword If      ${i} == 2           Handle New Window
            Exit For Loop If    ${i} == 3
    END

Navigate To TestProject
    Go To           https://testproject.io/

Click On Addons And Search
    click element         //a[@id='cc-button']
    Click Element         //a[@title='Platform']
    Click Element         //a[.='Addons']
    Click Element         //button[@aria-label='Close']
    Input Text            //input[@id='q']        Rest
    wait until element is visible  locator=//div[contains(text(), 'RESTful API Client')]    timeout=5s
    Click Element         //div[contains(text(), 'RESTful API Client')]
    ${language}=          Get Text                //div[@class='addon-language']
    Should Be Equal As Strings                 ${language}     Java

Random Actions
    Go To           https://www.google.com/
    Input Text      //input[@name='q']       TestProject
    press keys      //input[@name='q']       ENTER
    page should contain                      Free Test
    reload page
    log title
    ${links}=       Get All Links
    log to console  ${links}

*** Keywords ***
Init
    ${remoteUrl}                Set Variable        http://${browserstack_userName}:${browserstack_accessKey}@hub-cloud.browserstack.com/wd/hub
    ${desiredCapabilities}      Create Dictionary   os=${os}     os_version=${osVersion}     browserName=${browser}   browser_version=${browserVersion}     cloud:URL=${remoteUrl}
    Init Testproject Driver     chrome     url=https://tp-solutions.herokuapp.com/code      desired_capabilities=${desiredCapabilities}

Close
    Close All Browsers

BrowserStack
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}    add_argument    headless
    Call Method    ${chrome_options}    add_argument    disable-gpu
    [Return]       ${chrome_options}

Equals
    [Arguments]                     ${x}    ${y}
    Should Be Equal As Strings      ${x}    ${y}

Handle New Window
    Switch Window                       locator=NEW
    close window
    Switch Window                       locator=MAIN

*** Variables ***
${baseUrl}                     https://www.google.com/
${os}                          windows
${osVersion}                   10
${browser}                     chrome
${browserVersion}              91
${browserstack_userName}       Your_Username
${browserstack_accessKey}      Your_AccessKey

Regarding running mobile tests - we will consider adding support for that (: