2014年10月14日 星期二

robotframework demo 2 (selenium2library)

In  robotframework demo 1,  we define parameter.txt and key word.txt.  Follow those define, I desing  demo 2 to understand  Suite Setup、Suite Teardown 、Test Setup、Test Template

1. Create search_demo2 file

On Google_Demo, select this suite, right click on it and then click on New Suite

Enter  ->  search_demo2
Type ->   File
Format  ->  TXT

2. Edit search_demo2



 *** Settings ***
Suite Setup       Open Google web
Suite Teardown    Close Browser
Test Setup        Go to    ${Server}
Test Template     Input Search keyword
Resource          resource/keyword.txt

*** Test Cases ***    Keyword
keyword1              yahoo

keyword2              youtube

keyword3              python3

keyword4              ${KEYWORD}

keyword5              java

*** Keywords ***
Input Search keyword
    [Arguments]    ${key}
    Click Element    xpath=//*[@id="lst-ib"]
    Input Text    lst-ib    ${key}
    Press Key    xpath=//*[@id="lst-ib"]    \\27
    Click Button    xpath=//*[@id="tsf"]/div[2]/div[3]/center/input[1]
    Sleep    2


To Explain:

Suite Setup:  Start the test operation
Suite Teardown:   End the test operation
Test Setup:    Every test case start point
Test Template:   Every test case operation















3. Run search_demo2

robotframework demo 1 (selenium2library)

啟動 robotframework IDE


$ ride.py

1. Create a Google_Demo project
File -> New Project


Enter  ->  Google_Demo 
Type -> Directory
Format  ->  TXT

左邊視窗將會多一個 google demo 資料夾

2.  Create a New Suite (resource folder)

On Google_Demo, select this suite, right click on it and then click on New Suite

Enter  ->  resource
Type -> Directory
Format  ->  TXT

3. Create two Resource file  (parameter.txt and keyword.txt) 

On resource, select this suite, right click on it and then click on New Resource

Enter  ->  parameter
Format  ->  TXT

select resource again


Enter  ->  keyword
Format  ->  TXT

The Folder structure will like this picture



4. Edit parameter.txt ->  this file put parameter of your define
Content will like this


*** 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 Selenium2Library.

*** Variables ***
${SERVER}         http://www.google.com.tw
#${BROWSER}       Firefox
${BROWSER}        Chrome
${DELAY}          0.5
${WIDTH}          1024
${HIGHT}          768
${KEYWORD}        robotframework

*** Keywords ***


To Explain :

${SERVER}     =>  you defind web
${BROWSER} =>  you open browser
${DELAY}       =>  For run speed seconds
${WIDTH}       =>  Defind you browser window size
${HIGHT}        =>  Defind you browser window size
${KEYWORD}  =>  Search Key word

5. Edit keyword.txt ->  this file put you define keywords


*** Settings ***
Library           Selenium2Library
Resource          parameter.txt

*** Keywords ***
Open Google web
    Open Browser    ${SERVER}    ${BROWSER}
    Set Window Size    ${WIDTH}    ${HIGHT}
    Set Selenium Speed    ${DELAY}


To Explain :

Open Google web  => you define key word

Open Browser 、 Set Window Size 、 Set Selenium Speed =>  selenium2library key word

PS: if you don't know selenium2library key words、 you cau press F5, will pop a window, you can search key word and how to use the key word.


6. Create search_demo1 file

On Google_Demo, select this suite, right click on it and then click on New Suite

Enter  ->  search_demo1
Type ->   File
Format  ->  TXT

7. Edit search_demo1


*** Settings ***
Resource          resource/keyword.txt

*** Test Cases ***
Search Test
    Open Google Web
    Click Element    xpath=//*[@id="lst-ib"]
    Input Text    lst-ib    ${KEYWORD}
    Press Key    xpath=//*[@id="lst-ib"]    \\27
    Click Button    xpath=//*[@id="tsf"]/div[2]/div[3]/center/input[1]
    Sleep    3
    [Teardown]    Close Browser


To Explain:

Open Google Web  =>  Define from keyword.txt


Clilck Element  =>  define from library and xpath you can open chrome browse and use F12 function   to  search xpath and copy xpath。


Input Text  =>  define from library,  lst-ib is the element id,  ${KEYWORD} define from parameter.txt


Press Key => use key board function, xpath same as Click Element, \\27 is ASCII code, 27 is keybord esc.

Click Button => use mouse click the search button










8. Run Search_demo1
$ pybot Search_demo1.txt

2014年10月7日 星期二

Install robot framework IDE (os ubuntu 14.04)

In ubuntu 14.04

$ sudo aptitude install python-pip -y
$ sudo pip install robotframework
$ sudo pip install robotframework-selenium2library
$ sudo aptitude install wx2.8-headers libwxgtk2.8-0 libwxgtk2.8-dev python-wxgtk2.8 python-wxversion -y
$ sudo pip install robotframework-ride

下載 chrome web driver http://chromedriver.storage.googleapis.com/index.html

choice your version and download it.

Extract the file and folder has a file chromedriver

copy chromedriver to /usr/bin


sudo cp chromedrive /usr/bin

啟動 ridy

$ ridy.py &