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