Skip to content

Commit 58a3e75

Browse files
yichi.lusebgoa
authored andcommitted
CLOUDSTACK-6015 add Apache license header
Signed-off-by: Sebastien Goasguen <runseb@gmail.com>
1 parent 3800728 commit 58a3e75

17 files changed

Lines changed: 590 additions & 30 deletions

File tree

test/selenium/browser/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.

test/selenium/browser/firefox.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
from selenium import webdriver
219
import time
320
from selenium.common.exceptions import WebDriverException

test/selenium/common/Global_Locators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
################################################################################################################################################################################################
7474

7575
## Instances Page
76-
## Instances Main page
76+
## Instances Main page
7777

7878

7979
# Add Instance Button on top right corner of Instances page
@@ -166,7 +166,7 @@
166166
Offering_editname_name = "name"
167167

168168
# Edit description box
169-
Offering_editdescription_name = "displaytext"
169+
Offering_editdescription_name = "displaytext"
170170

171171
# Edit finished click ok
172172
Offering_editdone_css="div.button.done"

test/selenium/common/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+

test/selenium/common/shared.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
#!/usr/bin/python
219
# coding: latin-1
320

@@ -29,7 +46,7 @@ def try_except(*args, **kwargs):
2946
print repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
3047

3148
return try_except
32-
49+
3350
class Shared(object):
3451

3552
@staticmethod
@@ -58,8 +75,8 @@ def option_selection(browser, element_type, element_name, option_text, wait_elem
5875

5976
if len(wait_element_type) > 0 and len(wait_element_name) > 0:
6077
Shared.wait_for_element(browser, wait_element_type, wait_element_name)
61-
return ret
62-
78+
return ret
79+
6380
@staticmethod
6481
@try_except_decor
6582
def flash_message(browser):
@@ -107,28 +124,28 @@ def wait_for_element(browser, element_type, name, waittime = 30):
107124
wait.until(EC.presence_of_element_located((By.XPATH, name)))
108125
elif element_type.lower() == 'link_text':
109126
wait.until(EC.presence_of_element_located((By.LINK_TEXT, name)))
110-
127+
111128
#feed the string through directly
112129
else:
113130
wait.until(EC.presence_of_element_located(element_type, name))
114-
131+
115132
time.sleep(1)
116-
133+
117134
def playing_around(self):
118135
from threading import Timer
119136
t = Timer(20,self.wait_for_invisible)
120137
t.start()
121-
138+
122139
@staticmethod
123-
#wait until something disappears
140+
#wait until something disappears
124141
def wait_for_invisible(browser, element_type, name, waittime=30):
125142
wait = WebDriverWait(browser, waittime)
126-
143+
127144
# the code base uses underscores, but the real string doesn't have em.
128145
final_type = re.sub('_',' ',element_type)
129-
146+
130147
wait.until(EC.invisibility_of_element_located((final_type, name)))
131-
148+
132149
#this method isn't as slick as I hoped :(
133150
time.sleep(1)
134-
151+

test/selenium/cspages/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
class DashboardPage(object):
27+
28+
def __init__(self, browser):
29+
self.browser = browser
30+
self.active_item = ""
31+
self.items = []
32+
33+
@try_except_decor
34+
def get_active_item(self):
35+
self.active_item = ""
36+
lis = self.browser.find_elements_by_xpath("//*[@id='navigation']/ul/li")
37+
for li in lis:
38+
if li.get_attribute('class').find('active') > 0:
39+
self.active_item = li.get_attribute('class')[:(li.get_attribute('class').index(' active'))]
40+
return self.active_item
41+
42+
@try_except_decor
43+
def get_items(self):
44+
lis = self.browser.find_elements_by_xpath("//*[@id='navigation']/ul/li")
45+
for li in lis:
46+
item = li.get_attribute('class')[len('navigation-item '):]
47+
if item.find('active') > 0:
48+
item = item[:(item.index(' active'))]
49+
if item.find('first') > 0:
50+
item = item[:(item.index(' first'))]
51+
if item.find('last') > 0:
52+
item = item[:(item.index(' last'))]
53+
self.items.append(item.lower())
54+
return self.items
55+
# import pdb
56+
# pdb.set_trace()
57+
58+
@try_except_decor
59+
def navigate_to(self, item_name):
60+
if len(self.items) == 0:
61+
self.get_items()
62+
if item_name is None or len(item_name) == 0 or \
63+
item_name.lower() not in self.items or \
64+
(len(self.active_item) > 0 and self.active_item.lower().find(item_name.lower()) > 0):
65+
return
66+
67+
lis = self.browser.find_elements_by_xpath("//*[@id='navigation']/ul/li")
68+
for li in lis:
69+
if li.get_attribute('class').lower().find(item_name.lower()) > 0:
70+
li.click()
71+
time.sleep(3)
72+
return
73+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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

Comments
 (0)