|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +from selenium import webdriver |
| 19 | +from selenium.common.exceptions import * |
| 20 | +from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 |
| 21 | +from selenium.webdriver.common.action_chains import ActionChains as action |
| 22 | +from common import Global_Locators |
| 23 | + |
| 24 | +from common.shared import * |
| 25 | + |
| 26 | +import pdb |
| 27 | + |
| 28 | +class LoginPage(object): |
| 29 | + def __init__(self, browser): |
| 30 | + self.browser = browser |
| 31 | + self.username = "" |
| 32 | + self.password = "" |
| 33 | + self.language = "" |
| 34 | + |
| 35 | + @try_except_decor |
| 36 | + def set_username(self, username): |
| 37 | + self.username = username |
| 38 | + usernameElement = self.browser.find_element_by_css_selector(Global_Locators.login_username_css) |
| 39 | + usernameElement.send_keys(self.username) |
| 40 | + |
| 41 | + @try_except_decor |
| 42 | + def set_password(self, password): |
| 43 | + self.password = password |
| 44 | + passwordElement = self.browser.find_element_by_css_selector(Global_Locators.login_password_css) |
| 45 | + passwordElement.send_keys(self.password) |
| 46 | + self.pwelement = passwordElement |
| 47 | + |
| 48 | + @try_except_decor |
| 49 | + def set_language(self, language): |
| 50 | + self.language = language |
| 51 | + options = self.browser.find_elements_by_xpath('/html/body/div[3]/form/div[2]/div[4]/select/option') |
| 52 | + for option in options: |
| 53 | + if len(option.get_attribute('text')) > 0 and option.get_attribute('text').lower() == language.lower(): |
| 54 | + option.click() |
| 55 | + break |
| 56 | + |
| 57 | + @try_except_decor |
| 58 | + def login(self, expect_fail = False): |
| 59 | + if self.username == "" or self.password == "": |
| 60 | + print "Must set email and password before logging in" |
| 61 | + return |
| 62 | + loginElement = self.browser.find_element_by_css_selector(Global_Locators.login_submit_css) |
| 63 | + loginElement.click() |
| 64 | + |
| 65 | + time.sleep(3) |
| 66 | + try: |
| 67 | + # in case we have that "Hello and Welcome to CloudStack" page |
| 68 | + ele = None |
| 69 | + ele = self.browser.find_element_by_xpath("//input[@type='submit' and @class='button goTo advanced-installation' and @value='I have used CloudStack before, skip this guide']") |
| 70 | + if ele is not None: |
| 71 | + ele.click() |
| 72 | + time.sleep(2) |
| 73 | + except NoSuchElementException as err: |
| 74 | + pass |
| 75 | + |
| 76 | + @try_except_decor |
| 77 | + def logout(self, directly_logout = False): |
| 78 | + |
| 79 | + self.browser.set_window_size(1200,980) |
| 80 | + Shared.wait_for_element(self.browser, 'id', 'user') |
| 81 | + |
| 82 | + # must click this icon options first |
| 83 | +# pdb.set_trace() |
| 84 | + if directly_logout == False: |
| 85 | + try: |
| 86 | + ele = self.browser.find_element_by_xpath("//div[@id='user-options' and @style='display: block;']") |
| 87 | + if ele is None: |
| 88 | + ele1 = self.browser.find_element_by_xpath("//div[@id='user' and @class='button']/div[@class='icon options']/div[@class='icon arrow']").click() |
| 89 | + except NoSuchElementException as err: |
| 90 | + ele1 = self.browser.find_element_by_xpath("//div[@id='user' and @class='button']/div[@class='icon options']/div[@class='icon arrow']").click() |
| 91 | + |
| 92 | + # this is for cs 4.2.0-2 |
| 93 | +# ele2 = self.browser.find_element_by_xpath("//div[@id='header']/div[@id='user-options']") |
| 94 | + # this is for cs 4.4.0 |
| 95 | + ele2 = self.browser.find_element_by_xpath("//div[@id='user' and @class='button']/div[@id='user-options']/a[1]").click() |
| 96 | + |
| 97 | + Shared.wait_for_element(self.browser, 'class_name', 'login') |
| 98 | + |
| 99 | + @try_except_decor |
| 100 | + def get_error_msg(self, loginpage_url): |
| 101 | + if loginpage_url is not None and len(loginpage_url) > 0 and \ |
| 102 | + (self.browser.current_url.find(loginpage_url) > -1 or loginpage_url.find(self.browser.current_url) > -1): |
| 103 | + ele = self.browser.find_element_by_id('std-err') |
| 104 | + return ele.text |
| 105 | + else: |
| 106 | + return "" |
0 commit comments