Add a missing keyword
[integration/test.git] / csit / libraries / GUIKeywords.robot
1 *** Settings ***
2 Documentation     A resource file containing all global
3 ...               elements (Variables, keywords) to help
4 ...               DLUX csit testing.
5 Library           OperatingSystem
6 Library           Process
7 Library           Selenium2Library    timeout=30    implicit_wait=30    run_on_failure=Selenium2Library.Log Source
8 Resource          ../variables/Variables.robot
9 Resource          Utils.robot
10
11 *** Variables ***
12 ${BROWSER}        phantomjs
13 ${BASE_URL}       http://${ODL_SYSTEM_IP}:${RESTCONFPORT}/index.html
14 ${LOGIN_URL}      ${BASE_URL}#/login
15 ${XVFB_PORT}      99
16 ${LOGGED_URL}     ${BASE_URL}#/topology
17 ${LOGIN_USERNAME}    admin
18 ${LOGIN_PASSWORD}    admin
19 ${INVALID_USER}    invaliduser
20 ${INVALID_PWD}    invalidpwd
21 # Login page
22 ${OPENDAYLIGHT_IMAGE}    //img[@alt='OpenDayLight']
23 ${LOGIN_USERNAME_INPUT_FIELD}    //form/fieldset/div/input[@name='username']
24 ${LOGIN_PASSWORD_INPUT_FIELD}    //form/fieldset/div[2]/input[@name='password']
25 ${REMEMBER_ME_CHECKBOX}    //div[@class="checkbox"]
26 ${LOGIN_BUTTON}    //fieldset/button
27 ${PLEASE_SIGN_IN_PANEL}    //div/h3[contains(text(),"${PLEASE_SIGN_IN_MSG}")]
28 ${PLEASE_SIGN_IN_MSG}    Please Sign In
29 ${LOGIN_ERROR_MSG}    Unable to login
30 # DLUX Home page
31 ${TOPOLOGY_SUBMENU}    //a[@href='#/topology']
32 ${NODES_SUBMENU}    //a[@href='#/node/index')]
33 ${YANG_UI_SUBMENU}    //a[@href='#/yangui/index']
34 ${YANG_VISUALIZER_SUBMENU}    //a[@href='#/yangvisualizer/index']
35 ${YANGMAN_SUBMENU}    //a[@href='#/yangman/index']
36 # Topology Submenu
37 ${TOPOLOGY_SUBMENU_URL}    ${BASE_URL}#/topology
38 ${RELOAD_BUTTON}    //button[@ng-click='createTopology()']
39 ${CONTROLS_TEXT}    //div[@class="col-md-2"]/h3
40 # Nodes Submenu
41 ${NODES_SUBMENU_URL}    ${BASE_URL}#/node/index
42 # Yang UI Submenu
43 ${YANG_UI_SUBMENU_URL}    ${BASE_URL}#/yangui/index
44 # Yang Visualizer Submenu
45 ${YANG_VISUALIZER_SUBMENU_URL}    ${BASE_URL}#/yangvisualizer/index
46 # Yangman Submenu
47 ${YANGMAN_SUBMENU_URL}    ${BASE_URL}#/yangman/index
48 # Failback variables
49 ${USE_XVFB}       True
50 ${BROWSER_NAME}    phantomjs-1.9.8-linux-x86_64
51 ${BROWSER_EXT}    tar.bz2
52 ${BROWSER_FILE_NAME}    ${BROWSER_NAME}.${BROWSER_EXT}
53 ${BROWSER_URL}    https://bitbucket.org/ariya/phantomjs/downloads/${BROWSER_FILE_NAME}
54 ${BROWSER_PATH_EXECUTABLE}    ${BROWSER_NAME}/bin/phantomjs
55
56 *** Keywords ***
57 Check If Phantom Is Downloaded
58     [Documentation]    Checks if a folder named 'phantomjs' is found in the robot script directory.
59     ...    Checks if PhantomJS already been downloaded. This check is done by listing the directory and
60     ...    verification if there is one containing the word 'phantomjs'. Result is that the PhantomJS
61     ...    compressed file is downloaded and uncompressed locally related to the path of the running script.
62     ${installed}=    OperatingSystem.Run    ls -d */ | grep -m 1 phantomjs
63     [Return]    ${installed}
64
65 Download PhantomJS
66     [Documentation]    Downloads and uncompress the headless browser PhantomJS.
67     Process.Run Process    wget    ${BROWSER_URL}
68     Process.Run Process    tar    -jxf    ${BROWSER_FILE_NAME}
69
70 Get Headless Browser Path
71     [Documentation]    Returns the path of the executable headless browser.
72     ${is_downloaded}=    Check If Phantom Is Downloaded
73     BuiltIn.Run Keyword If    "${is_downloaded}"=="${EMPTY}"    Download PhantomJS
74     ${path}=    BuiltIn.Set Variable    ${EXECDIR}/${BROWSER_PATH_EXECUTABLE}
75     [Return]    ${path}
76
77 Open Headless Browser
78     [Arguments]    ${url}
79     [Documentation]    Failback browser, download and use the WebKit headless browser PhantomJS.
80     BuiltIn.Log    \n Using failback browser    console=yes
81     BuiltIn.Set Global Variable    ${USE_XVFB}    False
82     ${executable_path}=    Get Headless Browser Path
83     Selenium2Library.Create Webdriver    PhantomJS    executable_path=${executable_path}
84     Selenium2Library.Go To    ${url}
85
86 Set Display Port
87     [Arguments]    ${port}=${XVFB_PORT}
88     [Documentation]    Sets the environment variable used by xvfb and the browser.
89     OperatingSystem.Set Environment Variable    DISPLAY    :${port}
90
91 Open Virtual Display
92     [Documentation]    Starts xvfb, a kind-ish x-server on RAM.
93     Process.Start Process    Xvfb    :${XVFB_PORT}    -ac    -screen    0    1280x1024x16
94     ...    alias=xvfb
95     ${display}=    OperatingSystem.Get Environment Variable    DISPLAY    ${EMPTY}
96     BuiltIn.Run Keyword Unless    "${display}"==":${XVFB_PORT}"    Set Display Port
97
98 Close DLUX And Terminate XVFB Process If Running
99     [Documentation]    Closes all browser instances and terminates Xvfb if the process is running.
100     Selenium2Library.Close All Browsers
101     BuiltIn.Run Keyword If    ${USE_XVFB}    Terminate Process    xvfb
102
103 Launch DLUX
104     [Documentation]    Launches with a delay to let the page load. If it cannot run the default browser, it will download
105     ...    PhantomJS and use it instead. Steps of Launch DLUX are the following:
106     ...    1. Trying to start Xvfb and load the browser defined by the variable ${BROWSER}.
107     ...    2. If failed to start one of those task:
108     ...    2.1 Download and extract PhantomJS if not already done
109     ...    2.2 Create a custom PhantomJS webdriver based on the downloaded one
110     ...    3. Go to DLUX login URL and wait until the HTML page contains a specific element.
111     ${status}=    BuiltIn.Run Keyword And Return Status    Run Keywords    Open Virtual Display
112     ...    AND    Selenium2Library.Open Browser    ${LOGIN_URL}    ${BROWSER}
113     BuiltIn.Run Keyword Unless    ${status}    Open Headless Browser    ${LOGIN_URL}
114     Selenium2Library.Wait Until Page Contains Element    css=div.container
115
116 Open DLUX Login Page
117     [Arguments]    ${LOGIN URL}
118     [Documentation]    Loads DLUX login page.
119     Selenium2Library.Open Browser    ${LOGIN_URL}    ${BROWSER}
120     Selenium2Library.Maximize Browser Window
121     Selenium2Library.Wait Until Page Contains Element    ${PLEASE_SIGN_IN_PANEL}
122
123 Verify Elements Of DLUX Login Page
124     [Documentation]    Verifies elements presence in DLUX login page.
125     Selenium2Library.Page Should Contain Image    ${OPENDAYLIGHT_IMAGE}
126     Selenium2Library.Page Should Contain Element    ${LOGIN_USERNAME_INPUT_FIELD}
127     Selenium2Library.Page Should Contain Element    ${LOGIN_PASSWORD_INPUT_FIELD}
128     Selenium2Library.Page Should Contain Element    ${REMEMBER_ME_CHECKBOX}
129     Selenium2Library.Page Should Contain Element    ${LOGIN_BUTTON}
130
131 Log In To DLUX
132     [Arguments]    ${username}    ${password}
133     [Documentation]    Inserts username and password and logs in DLUX.
134     Selenium2Library.Focus    ${LOGIN_USERNAME_INPUT_FIELD}
135     Selenium2Library.Input Text    ${LOGIN_USERNAME_INPUT_FIELD}    ${username}
136     Selenium2Library.Focus    ${LOGIN_PASSWORD_INPUT_FIELD}
137     Selenium2Library.Input Text    ${LOGIN_PASSWORD_INPUT_FIELD}    ${password}
138     Focus And Click Element    ${LOGIN_BUTTON}
139
140 Log In To DLUX With Invalid Credentials
141     [Arguments]    ${username}    ${password}
142     [Documentation]    Tries to log in to DLUX with invalid credentials and verifies occurence of the error message.
143     Selenium2Library.Focus    ${LOGIN_USERNAME_INPUT_FIELD}
144     Selenium2Library.Input Text    ${LOGIN_USERNAME_INPUT_FIELD}    ${username}
145     Selenium2Library.Focus    ${LOGIN_PASSWORD_INPUT_FIELD}
146     Selenium2Library.Input Text    ${LOGIN_PASSWORD_INPUT_FIELD}    ${password}
147     Focus And Click Element    ${LOGIN_BUTTON}
148     Selenium2Library.Location Should Be    ${LOGIN_URL}
149     Selenium2Library.Wait Until Page Contains    ${LOGIN_ERROR_MSG}
150
151 Open Or Launch DLUX
152     [Documentation]    Tries to open Dlux login page. If it fails, then launches Dlux using xvfb or headless browser.
153     ${status}=    BuiltIn.Run Keyword And Return Status    Open DLUX Login Page    ${LOGIN_URL}
154     BuiltIn.Run Keyword If    "${status}"=="False"    Launch DLUX
155     Verify Elements Of DLUX Login Page
156
157 Open Or Launch DLUX Page And Log In To DLUX
158     [Documentation]    Opens or launches Dlux and then logs in to Dlux.
159     Open Or Launch DLUX
160     Log In To DLUX    ${LOGIN_USERNAME}    ${LOGIN_PASSWORD}
161
162 Navigate To URL
163     [Arguments]    ${url}
164     [Documentation]    Goes to the defined URL provided in an argument.
165     ${status}=    BuiltIn.Run Keyword And Return Status    Selenium2Library.Location Should Be    ${url}
166     BuiltIn.Run Keyword Unless    ${status}    Selenium2Library.Go To    ${url}
167
168 Focus And Click Element
169     [Arguments]    ${element}
170     [Documentation]    Clicks the element with previous element visibility check and element focus.
171     Selenium2Library.Wait Until Element Is Visible    ${element}
172     Selenium2Library.Focus    ${element}
173     Selenium2Library.Mouse Over    ${element}
174     Selenium2Library.Click Element    ${element}
175
176 Mouse Down And Mouse Up Click Element
177     [Arguments]    ${element}
178     [Documentation]    Clicks the element by imitating mouse left button click down and click up.
179     Selenium2Library.Wait Until Page Contains Element    ${element}
180     Selenium2Library.Focus    ${element}
181     Selenium2Library.Mouse Over    ${element}
182     Selenium2Library.Mouse Down    ${element}
183     Selenium2Library.Mouse Up    ${element}
184
185 Page Should Contain Element With Wait
186     [Arguments]    ${element}
187     [Documentation]    Similar to Selenium2Library.Wait Until Page Contains Element but returns web page source code when fails.
188     BuiltIn.Wait Until Keyword Succeeds    1 min    5 sec    Selenium2Library.Page Should Contain Element    ${element}
189
190 Helper Click
191     [Arguments]    ${element_to_be_clicked}    ${element_to_be_checked}
192     [Documentation]    Clicks the ${element_to_be_clicked} and verifies that page contains ${element_to_be_checked}.
193     Selenium2Library.Focus    ${element_to_be_clicked}
194     Selenium2Library.Click Element    ${element_to_be_clicked}
195     Selenium2Library.Wait Until Page Contains Element    ${element_to_be_checked}
196
197 Patient Click
198     [Arguments]    ${element_to_be_clicked}    ${element_to_be_checked}
199     [Documentation]    Combines clicking ${element_to_be_clicked} and checking that ${element_to_be_checked} is visible with
200     ...    BuiltIn.Wait Until Keyword Succeeds keyword in order to secure reliable execution of Selenium2Library.Click Element
201     ...    keyword in AngularJS webapp.
202     BuiltIn.Wait Until Keyword Succeeds    1 min    5 sec    Helper Click    ${element_to_be_clicked}    ${element_to_be_checked}