Permalink
Browse files

Merge remote branch webdriver into local webdriver.

  • Loading branch information...
2 parents a09687a + 135725f commit be87d307a320bd2f4fe7b284968a20ab68e71288 @guilhermechapiewski guilhermechapiewski committed Mar 31, 2010
View
@@ -30,6 +30,7 @@ all: prepare_build compile test report_success
test: prepare_build compile run_unit run_functional acceptance report_success
unit: prepare_build compile run_unit report_success
functional: prepare_build compile run_functional report_success
+acceptance: acceptance_selenium acceptance_webdriver
prepare_build: clean create_build_dir
clean: remove_build_dir remove_dist_dir
@find . -name '*.pyc' -delete
@@ -90,17 +91,23 @@ wait:
@echo "========================="
@sleep ${wait_time}
-acceptance:
+acceptance_selenium:
@make selenium_up
@make wait
- @echo "================="
- @echo "Starting tests..."
- @echo "================="
-
- @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*en-us.acc" -l en-us -v 3
- @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*pt-br.acc" -l pt-br -v 3
+ @echo "=========================="
+ @echo "Starting Selenium tests..."
+ @echo "=========================="
+ @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*en-us.acc" -l en-us -v 1
+ @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*pt-br.acc" -l pt-br -v 1
@-make selenium_down
+acceptance_webdriver:
+ @echo "==========================="
+ @echo "Starting WebDriver tests..."
+ @echo "==========================="
+ @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*en-us.acc" -l en-us -v 1 -e "webdriver"
+ @PYTHONPATH=`pwd`/pyccuracy/:$$PYTHONPATH python pyccuracy/pyccuracy_console.py -d ${root_dir}/tests/acceptance/action_tests/ -p "*pt-br.acc" -l pt-br -v 1 -e "webdriver"
+
dist: clean
@echo "Running a build..."
@python setup.py sdist
@@ -96,7 +96,7 @@ class ElementIsNotVisibleAction(ActionBase):
def execute(self, context, element_type, element_name):
element_key = resolve_element_key(context, element_type, element_name, self.resolve_element_key)
-
+
error_message = context.language.format("element_is_not_visible_failure", element_type, element_name)
self.assert_element_is_not_visible(context, element_key, error_message)
@@ -28,9 +28,9 @@
class WebDriverDriver(BaseDriver):
backend = 'webdriver'
- def __init__(self, context, selenium=None):
+ def __init__(self, context, webdriver=None):
self.context = context
- self.selenium = selenium
+ self.webdriver = webdriver
def start_test(self, url=None):
self.webdriver = WebDriver()
@@ -47,16 +47,58 @@ def page_open(self, url):
self.webdriver.get(url)
def wait_for_page(self, timeout=10000):
- # Does not make sense for WebDriver.
+ # Does not make sense for WebDriver because it always wait for page to load.
pass
def click_element(self, element_selector):
self.webdriver.find_element_by_xpath(element_selector).click()
def get_title(self):
return self.webdriver.get_title()
-
- #TODO
+
+ def check_css_style_is_visible(self, style):
+ styles = style.split(';')
+ for each_style in [s for s in styles if s != '']:
+ name, value = each_style.split(':')
+ name = name.strip().lower()
+ value = value.strip().lower()
+ if (name == 'visibility' and value == 'hidden') or (name == 'display' and value == 'none'):
+ return False
+ return True
+
+ # TODO: REALLY poor performance, there must be a better way to do that hacking WebDriver
+ def is_element_visible_by_css(self, element):
+ style = ''
+ try:
+ style = element.get_attribute('style')
+ except ErrorInResponseException, e:
+ # if there was an error, assume that there's no style and continue
+ pass
+
+ parent = None
+ has_parent = True
+
+ while has_parent:
+ try:
+ parent = element.find_element_by_xpath('..')
+ except ErrorInResponseException, e:
+ # if there was an error, assume that there's no parent anymore and return
+ has_parent = False
+ # returns when there is no more parents
+ return self.check_css_style_is_visible(style)
+
+ try:
+ style = '%s;%s' % (style, parent.get_attribute('style'))
+ # returns when finds out that it's not visible
+ if not self.check_css_style_is_visible(style):
+ return False
+ except ErrorInResponseException, e:
+ # if there was an error, assume that there's no style and continue
+ pass
+
+ # next
+ element = parent
+
def is_element_visible(self, element_selector):
try:
element = self.webdriver.find_element_by_xpath(element_selector)
@@ -67,9 +109,7 @@ def is_element_visible(self, element_selector):
except ElementNotVisibleException, e:
return False
-# visible = self.exec_js('argument[0].style.visibility != "hidden" && argument[0].style.display != "none"', element)
-# return visible == 'true'
- return True
+ return self.is_element_visible_by_css(element)
def is_element_enabled(self, element_selector):
return self.webdriver.find_element_by_xpath(element_selector).is_enabled()
@@ -99,16 +139,15 @@ def wait_for_element_to_disappear(self, element_selector, timeout):
return False
def get_element_text(self, element_selector):
- return self.webdriver.find_element_by_xpath(element_selector).get_text()
+ return self.webdriver.find_element_by_xpath(element_selector).get_value()
def get_element_markup(self, element_selector):
elem = self.webdriver.find_element_by_xpath(element_selector)
return self.exec_js('argument[0].innerHTML', elem)
def drag_element(self, from_element_selector, to_element_selector):
- # self.selenium.drag_and_drop_to_object(from_element_selector, to_element_selector)
- raise NotImplementedError('Unfortunately Webdriver does not support drag-n-drop yet. \
- If you really need it, you will have to use Selenium driver.')
+ raise NotImplementedError('Unfortunately Webdriver does not support drag-n-drop yet. ' + \
+ 'If you really need it, you will have to use Selenium driver.')
def mouseover_element(self, element_selector):
elem = self.webdriver.find_element_by_xpath(element_selector)
@@ -131,15 +170,14 @@ def checkbox_uncheck(self, checkbox_selector):
def get_selected_index(self, element_selector):
elem = self.webdriver.find_element_by_xpath(element_selector)
- return self.exec_js('argument[0].selectedIndex;' % index, elem)
+ return self.exec_js('argument[0].selectedIndex;', elem)
def get_selected_value(self, element_selector):
- elem = self.webdriver.find_element_by_xpath(element_selector)
- return self.exec_js('argument[0].options[argument[0].selectedIndex].value;' % index, elem)
+ return self.webdriver.find_element_by_xpath(element_selector).get_value()
def get_selected_text(self, element_selector):
elem = self.webdriver.find_element_by_xpath(element_selector)
- return self.exec_js('argument[0].options[argument[0].selectedIndex].innerText;' % index, elem)
+ return self.exec_js('argument[0].options[argument[0].selectedIndex].innerText;', elem)
def select_option_by_index(self, element_selector, index):
elem = self.webdriver.find_element_by_xpath(element_selector)
@@ -149,13 +187,13 @@ def select_option_by_value(self, element_selector, value):
elem = self.webdriver.find_element_by_xpath(element_selector)
for index, option in enumerate(elem.find_elements_by_xpath('option')):
if option.get_value() == value:
- self.select_option_by_index(index)
+ self.select_option_by_index(element_selector, index)
def select_option_by_text(self, element_selector, text):
elem = self.webdriver.find_element_by_xpath(element_selector)
for index, option in enumerate(elem.find_elements_by_xpath('option')):
if option.get_text() == text:
- self.select_option_by_index(index)
+ self.select_option_by_index(element_selector, index)
def is_element_empty(self, element_selector):
current_text = self.webdriver.find_element_by_xpath(element_selector).get_value()
No changes.
No changes.
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+# Licensed under the Open Software License ('OSL') v. 3.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.opensource.org/licenses/osl-3.0.php
+
+# 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 pyccuracy.drivers.core.webdriver_driver import WebDriverDriver
+
+def test_check_css_style_is_visible():
+ driver = WebDriverDriver(None)
+
+ assert driver.check_css_style_is_visible('')
+ assert not driver.check_css_style_is_visible('visibility: hidden;')
+ assert not driver.check_css_style_is_visible('visibility : hidden')
+ assert not driver.check_css_style_is_visible('display: none;')
+ assert not driver.check_css_style_is_visible('display:none')
+ assert not driver.check_css_style_is_visible('visibility: hidden; display: none;')
+ assert not driver.check_css_style_is_visible('DISPLAY: NONE;')

0 comments on commit be87d30

Please sign in to comment.