aboutsummaryrefslogtreecommitdiffstats
path: root/services/frontend/base_actions/get.py
blob: 8735c1b26296bb924cfb7cde08246cac07d39eb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
# ============LICENSE_START========================================== 
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
# under the Apache License, Version 2.0 (the “License”);
# you may not use this software except in compliance with the License.
# You may obtain a copy of the License at
#
#             http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
# Unless otherwise specified, all documentation contained herein is licensed
# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
# you may not use this documentation except in compliance with the License.
# You may obtain a copy of the License at
#
#             https://creativecommons.org/licenses/by/4.0/
#
# Unless required by applicable law or agreed to in writing, documentation
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
from services.frontend.base_actions.wait import Wait
from services.session import session


class Get:

    @staticmethod
    def by_id(attr_id_value, wait_for_page=False):
        try:
            if wait_for_page:
                Wait.page_has_loaded()
            Wait.id(attr_id_value)
            return session.ice_driver.find_element_by_id(attr_id_value).text
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to get text of element " + attr_id_value
            raise Exception(errorMsg, attr_id_value)

    @staticmethod
    def by_css(attr_css_value, wait_for_page=False):
        try:
            if wait_for_page:
                Wait.page_has_loaded()
            Wait.css(attr_css_value)
            return session.ice_driver.find_element_by_css_selector(attr_css_value).text
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to get text of element " + attr_css_value
            raise Exception(errorMsg, attr_css_value)

    @staticmethod
    def wysiwyg_element_by_id(attr_id_value):
        try:
            Wait.id(attr_id_value)
            return session.ice_driver.find_element_by_css_selector(
                "#" + attr_id_value + ".wysiwyg-textarea")
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to get element by id " + attr_id_value
            raise Exception(errorMsg, attr_id_value)

    @staticmethod
    def by_name(attr_name_value):
        try:
            Wait.name(attr_name_value)
            return session.ice_driver.find_element_by_name(attr_name_value).text
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to get text of element " + attr_name_value
            raise Exception(errorMsg, attr_name_value)

    @staticmethod
    def by_xpath(attr_name_value):
        try:
            Wait.xpath(attr_name_value)
            return session.ice_driver.find_element_by_xpath(attr_name_value).text
        # If failed - count the failure and add the error to list of errors.
        except Exception as e:
            errorMsg = "Failed to get text of element " + attr_name_value
            raise Exception(errorMsg, attr_name_value)

    @staticmethod
    def value_by_name(attr_name_value):
        try:
            Wait.name(attr_name_value)
            return session.ice_driver.find_element_by_name(attr_name_value).get_attribute("value")
        except Exception as e:
            errorMsg = "Failed to get value by name:" + attr_name_value
            raise Exception(errorMsg, attr_name_value)

    @staticmethod
    def meta_order_by_id(attr_id_value):
        try:
            Wait.id(attr_id_value)
            return session.ice_driver.find_element_by_id(attr_id_value).get_attribute("meta-order")
        except Exception as e:
            errorMsg = "Failed to get meta order by id:" + attr_id_value
            raise Exception(errorMsg, attr_id_value)

    @staticmethod
    def is_selected_by_id(attr_id_value, wait_for_page=False):
        try:
            if wait_for_page:
                Wait.page_has_loaded()
            Wait.id(attr_id_value)
            return session.ice_driver.find_element_by_id(attr_id_value).is_selected()
        except Exception as e:
            errorMsg = "Failed to get if it's selected by id:" + attr_id_value
            raise Exception(errorMsg, attr_id_value)