Skip to content

Commit

Permalink
Fix MobilePageObject error in python 3 and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed May 26, 2016
1 parent bd7582e commit d333fad
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 1 deletion.
1 change: 1 addition & 0 deletions toolium/driver_wrappers_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def _find_parent_directory(directory, filename):
parent_directory = os.path.join('..', parent_directory)
return os.path.abspath(directory)


@classmethod
def configure_visual_directories(cls, driver_info):
"""Configure screenshots, videos and visual directories
Expand Down
2 changes: 1 addition & 1 deletion toolium/pageobjects/mobile_page_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class IosPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME)
__class_name = cls.__name__.replace('Base', __os_name.capitalize())
return getattr(importlib.import_module(__module_name), __class_name)(__driver_wrapper)
else:
return super(MobilePageObject, cls).__new__(cls, driver_wrapper)
return super(MobilePageObject, cls).__new__(cls)
Empty file.
28 changes: 28 additions & 0 deletions toolium/test/pageobjects/android/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
u"""
Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file 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.
"""

from selenium.webdriver.common.by import By

from toolium.pageelements import *
from toolium.test.pageobjects.base.login import BaseLoginPageObject


class AndroidLoginPageObject(BaseLoginPageObject):
username = InputText(By.ID, 'username_id_android')
password = InputText(By.ID, 'password_id_android')
login_button = Button(By.ID, 'login_id_android')
Empty file.
26 changes: 26 additions & 0 deletions toolium/test/pageobjects/base/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
u"""
Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file 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.
"""

from toolium.pageobjects.mobile_page_object import MobilePageObject


class BaseLoginPageObject(MobilePageObject):
def login(self, username, password):
self.username = username
self.password = password
self.login_button.click()
Empty file.
28 changes: 28 additions & 0 deletions toolium/test/pageobjects/ios/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
u"""
Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file 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.
"""

from selenium.webdriver.common.by import By

from toolium.pageelements import *
from toolium.test.pageobjects.base.login import BaseLoginPageObject


class IosLoginPageObject(BaseLoginPageObject):
username = InputText(By.ID, 'username_id_ios')
password = InputText(By.ID, 'password_id_ios')
login_button = Button(By.ID, 'login_id_ios')
66 changes: 66 additions & 0 deletions toolium/test/pageobjects/test_mobile_page_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
u"""
Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
This file is part of Toolium.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file 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.
"""

import os
import unittest

from nose.tools import assert_is_instance, assert_equal, assert_true

from toolium.config_files import ConfigFiles
from toolium.driver_wrappers_pool import DriverWrappersPool
from toolium.test.pageobjects.android.login import AndroidLoginPageObject
from toolium.test.pageobjects.base.login import BaseLoginPageObject
from toolium.test.pageobjects.ios.login import IosLoginPageObject


class TestMobilePageObject(unittest.TestCase):
def setUp(self):
# Configure properties
config_files = ConfigFiles()
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
config_files.set_config_directory(os.path.join(root_path, 'conf'))
config_files.set_config_properties_filenames('properties.cfg')
self.driver_wrapper = DriverWrappersPool.get_default_wrapper()
self.driver_wrapper.configure(tc_config_files=config_files)

def test_mobile_page_object_ios(self):
self.driver_wrapper.config.set('Driver', 'type', 'ios')
page_object = BaseLoginPageObject(self.driver_wrapper)

# Check instance type, specific locator and common method
assert_is_instance(page_object, IosLoginPageObject)
assert_equal(page_object.username.locator[1], 'username_id_ios')
assert_true(hasattr(page_object, 'login'))

def test_mobile_page_object_android(self):
self.driver_wrapper.config.set('Driver', 'type', 'android')
page_object = BaseLoginPageObject(self.driver_wrapper)

# Check instance type, specific locator and common method
assert_is_instance(page_object, AndroidLoginPageObject)
assert_equal(page_object.username.locator[1], 'username_id_android')
assert_true(hasattr(page_object, 'login'))

def test_mobile_page_object_default(self):
self.driver_wrapper.config.set('Driver', 'type', 'unknown')
page_object = BaseLoginPageObject(self.driver_wrapper)

# Check instance type, specific locator and common method
assert_is_instance(page_object, AndroidLoginPageObject)
assert_equal(page_object.username.locator[1], 'username_id_android')
assert_true(hasattr(page_object, 'login'))

0 comments on commit d333fad

Please sign in to comment.