From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 01583E00D43; Thu, 14 Jul 2016 08:55:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [192.55.52.88 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 650DAE0095F for ; Thu, 14 Jul 2016 08:55:28 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 14 Jul 2016 08:55:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,363,1464678000"; d="asc'?scan'208";a="846331311" Received: from alimonb-mobl1.zpn.intel.com (HELO [10.219.5.159]) ([10.219.5.159]) by orsmga003.jf.intel.com with ESMTP; 14 Jul 2016 08:55:26 -0700 To: "Smith, Elliot" References: <1468353368-7065-1-git-send-email-anibal.limon@linux.intel.com> From: =?UTF-8?B?QW7DrWJhbCBMaW3Ds24=?= Message-ID: <5787B602.4030404@linux.intel.com> Date: Thu, 14 Jul 2016 10:55:46 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Cc: libertad.gonzalez.de.la.cruz@intel.com, toaster@yoctoproject.org Subject: Re: [PATCH 1/2] toaster/tests: browser rename selenium_helpers to selenium_helpers_base X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2016 15:55:32 -0000 X-Groupsio-MsgNum: 4971 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="KgiimtL3ICmH0UcNJDaE9d9P0WULOlJWd" --KgiimtL3ICmH0UcNJDaE9d9P0WULOlJWd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/14/2016 08:25 AM, Smith, Elliot wrote: > On 12 July 2016 at 20:56, An=C3=ADbal Lim=C3=B3n wrote: >=20 >> Do the raname in order to reuse selenium helper outside django >> environment. >> >=20 > Hello Anibal. >=20 > I'm not able to apply the first patch. I get a message about >=20 > "Reversed (or previously applied) patch detected! Assume -R?" >=20 > Regardless of whether I treat it as reversed or not, I can't apply it. >=20 > Could you pleas resubmit the patches, based on toaster-next? I think it= > would also be reasonable to merge the two patches together, as it's pre= tty > easy to see what's going on. I rebased the patches upon [1], also i merge into one patch [2], sending again... Thanks for look into it, alimon [1] http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=3Dtoaster-n= ext [2] http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=3Dalimon= /toaster&id=3D255f5da0627adae331fe6fe6b6936569479bd4cb >=20 > Also note that we tend to create the patches relative to the root of a = poky > checkout, rather than relative to the bitbake directory, though this is= a > minor issue. >=20 > Cheers. > Elliot >=20 >=20 >> >> Signed-off-by: An=C3=ADbal Lim=C3=B3n >> --- >> lib/toaster/tests/browser/selenium_helpers.py | 205 >> --------------------- >> lib/toaster/tests/browser/selenium_helpers_base.py | 205 >> +++++++++++++++++++++ >> 2 files changed, 205 insertions(+), 205 deletions(-) >> delete mode 100644 lib/toaster/tests/browser/selenium_helpers.py >> create mode 100644 lib/toaster/tests/browser/selenium_helpers_base.py= >> >> diff --git a/lib/toaster/tests/browser/selenium_helpers.py >> b/lib/toaster/tests/browser/selenium_helpers.py >> deleted file mode 100644 >> index 54db2e8..0000000 >> --- a/lib/toaster/tests/browser/selenium_helpers.py >> +++ /dev/null >> @@ -1,205 +0,0 @@ >> -#! /usr/bin/env python >> -# ex:ts=3D4:sw=3D4:sts=3D4:et >> -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- >> -# >> -# BitBake Toaster Implementation >> -# >> -# Copyright (C) 2013-2016 Intel Corporation >> -# >> -# This program is free software; you can redistribute it and/or modif= y >> -# it under the terms of the GNU General Public License version 2 as >> -# published by the Free Software Foundation. >> -# >> -# This program is distributed in the hope that it will be useful, >> -# but WITHOUT ANY WARRANTY; without even the implied warranty of >> -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> -# GNU General Public License for more details. >> -# >> -# You should have received a copy of the GNU General Public License a= long >> -# with this program; if not, write to the Free Software Foundation, I= nc., >> -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >> -# >> -# The Wait class and some of SeleniumDriverHelper and SeleniumTestCas= e are >> -# modified from Patchwork, released under the same licence terms as >> Toaster: >> -# >> https://github.com/dlespiau/patchwork/blob/master/patchwork/tests.brow= ser.py >> - >> -""" >> -Helper methods for creating Toaster Selenium tests which run within >> -the context of Django unit tests. >> -""" >> - >> -import os >> -import time >> - >> -from django.contrib.staticfiles.testing import StaticLiveServerTestCa= se >> -from selenium import webdriver >> -from selenium.webdriver.support.ui import WebDriverWait >> -from selenium.common.exceptions import NoSuchElementException, \ >> - StaleElementReferenceException, TimeoutException >> - >> -def create_selenium_driver(browser=3D'chrome'): >> - # set default browser string based on env (if available) >> - env_browser =3D os.environ.get('TOASTER_TESTS_BROWSER') >> - if env_browser: >> - browser =3D env_browser >> - >> - if browser =3D=3D 'chrome': >> - return webdriver.Chrome( >> - service_args=3D["--verbose", "--log-path=3Dselenium.log"]= >> - ) >> - elif browser =3D=3D 'firefox': >> - return webdriver.Firefox() >> - elif browser =3D=3D 'ie': >> - return webdriver.Ie() >> - elif browser =3D=3D 'phantomjs': >> - return webdriver.PhantomJS() >> - else: >> - msg =3D 'Selenium driver for browser %s is not available' % b= rowser >> - raise RuntimeError(msg) >> - >> -class Wait(WebDriverWait): >> - """ >> - Subclass of WebDriverWait with predetermined timeout and poll >> - frequency. Also deals with a wider variety of exceptions. >> - """ >> - _TIMEOUT =3D 10 >> - _POLL_FREQUENCY =3D 0.5 >> - >> - def __init__(self, driver): >> - super(Wait, self).__init__(driver, self._TIMEOUT, >> self._POLL_FREQUENCY) >> - >> - def until(self, method, message=3D''): >> - """ >> - Calls the method provided with the driver as an argument unti= l the >> - return value is not False. >> - """ >> - >> - end_time =3D time.time() + self._timeout >> - while True: >> - try: >> - value =3D method(self._driver) >> - if value: >> - return value >> - except NoSuchElementException: >> - pass >> - except StaleElementReferenceException: >> - pass >> - >> - time.sleep(self._poll) >> - if time.time() > end_time: >> - break >> - >> - raise TimeoutException(message) >> - >> - def until_not(self, method, message=3D''): >> - """ >> - Calls the method provided with the driver as an argument unti= l the >> - return value is False. >> - """ >> - >> - end_time =3D time.time() + self._timeout >> - while True: >> - try: >> - value =3D method(self._driver) >> - if not value: >> - return value >> - except NoSuchElementException: >> - return True >> - except StaleElementReferenceException: >> - pass >> - >> - time.sleep(self._poll) >> - if time.time() > end_time: >> - break >> - >> - raise TimeoutException(message) >> - >> -class SeleniumTestCase(StaticLiveServerTestCase): >> - """ >> - NB StaticLiveServerTestCase is used as the base test case so that= >> - static files are served correctly in a Selenium test run context;= see >> - >> https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#special= ized-test-case-to-support-live-testing >> - """ >> - >> - @classmethod >> - def setUpClass(cls): >> - """ Create a webdriver driver at the class level """ >> - >> - super(SeleniumTestCase, cls).setUpClass() >> - >> - # instantiate the Selenium webdriver once for all the test me= thods >> - # in this test case >> - cls.driver =3D create_selenium_driver() >> - cls.driver.maximize_window() >> - >> - @classmethod >> - def tearDownClass(cls): >> - """ Clean up webdriver driver """ >> - >> - cls.driver.quit() >> - super(SeleniumTestCase, cls).tearDownClass() >> - >> - def get(self, url): >> - """ >> - Selenium requires absolute URLs, so convert Django URLs retur= ned >> - by resolve() or similar to absolute ones and get using the >> - webdriver instance. >> - >> - url: a relative URL >> - """ >> - abs_url =3D '%s%s' % (self.live_server_url, url) >> - self.driver.get(abs_url) >> - >> - def find(self, selector): >> - """ Find single element by CSS selector """ >> - return self.driver.find_element_by_css_selector(selector) >> - >> - def find_all(self, selector): >> - """ Find all elements matching CSS selector """ >> - return self.driver.find_elements_by_css_selector(selector) >> - >> - def focused_element(self): >> - """ Return the element which currently has focus on the page = """ >> - return self.driver.switch_to.active_element >> - >> - def wait_until_present(self, selector): >> - """ Wait until element matching CSS selector is on the page "= "" >> - is_present =3D lambda driver: self.find(selector) >> - msg =3D 'An element matching "%s" should be on the page' % se= lector >> - element =3D Wait(self.driver).until(is_present, msg) >> - return element >> - >> - def wait_until_visible(self, selector): >> - """ Wait until element matching CSS selector is visible on th= e >> page """ >> - is_visible =3D lambda driver: self.find(selector).is_displaye= d() >> - msg =3D 'An element matching "%s" should be visible' % select= or >> - Wait(self.driver).until(is_visible, msg) >> - return self.find(selector) >> - >> - def wait_until_focused(self, selector): >> - """ Wait until element matching CSS selector has focus """ >> - is_focused =3D \ >> - lambda driver: self.find(selector) =3D=3D self.focused_el= ement() >> - msg =3D 'An element matching "%s" should be focused' % select= or >> - Wait(self.driver).until(is_focused, msg) >> - return self.find(selector) >> - >> - def enter_text(self, selector, value): >> - """ Insert text into element matching selector """ >> - # note that keyup events don't occur until the element is cli= cked >> - # (in the case of , for example), so >> simulate >> - # user clicking the element before inserting text into it >> - field =3D self.click(selector) >> - >> - field.send_keys(value) >> - return field >> - >> - def click(self, selector): >> - """ Click on element which matches CSS selector """ >> - element =3D self.wait_until_visible(selector) >> - element.click() >> - return element >> - >> - def get_page_source(self): >> - """ Get raw HTML for the current page """ >> - return self.driver.page_source >> diff --git a/lib/toaster/tests/browser/selenium_helpers_base.py >> b/lib/toaster/tests/browser/selenium_helpers_base.py >> new file mode 100644 >> index 0000000..54db2e8 >> --- /dev/null >> +++ b/lib/toaster/tests/browser/selenium_helpers_base.py >> @@ -0,0 +1,205 @@ >> +#! /usr/bin/env python >> +# ex:ts=3D4:sw=3D4:sts=3D4:et >> +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- >> +# >> +# BitBake Toaster Implementation >> +# >> +# Copyright (C) 2013-2016 Intel Corporation >> +# >> +# This program is free software; you can redistribute it and/or modif= y >> +# it under the terms of the GNU General Public License version 2 as >> +# published by the Free Software Foundation. >> +# >> +# This program is distributed in the hope that it will be useful, >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +# GNU General Public License for more details. >> +# >> +# You should have received a copy of the GNU General Public License a= long >> +# with this program; if not, write to the Free Software Foundation, I= nc., >> +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >> +# >> +# The Wait class and some of SeleniumDriverHelper and SeleniumTestCas= e are >> +# modified from Patchwork, released under the same licence terms as >> Toaster: >> +# >> https://github.com/dlespiau/patchwork/blob/master/patchwork/tests.brow= ser.py >> + >> +""" >> +Helper methods for creating Toaster Selenium tests which run within >> +the context of Django unit tests. >> +""" >> + >> +import os >> +import time >> + >> +from django.contrib.staticfiles.testing import StaticLiveServerTestCa= se >> +from selenium import webdriver >> +from selenium.webdriver.support.ui import WebDriverWait >> +from selenium.common.exceptions import NoSuchElementException, \ >> + StaleElementReferenceException, TimeoutException >> + >> +def create_selenium_driver(browser=3D'chrome'): >> + # set default browser string based on env (if available) >> + env_browser =3D os.environ.get('TOASTER_TESTS_BROWSER') >> + if env_browser: >> + browser =3D env_browser >> + >> + if browser =3D=3D 'chrome': >> + return webdriver.Chrome( >> + service_args=3D["--verbose", "--log-path=3Dselenium.log"]= >> + ) >> + elif browser =3D=3D 'firefox': >> + return webdriver.Firefox() >> + elif browser =3D=3D 'ie': >> + return webdriver.Ie() >> + elif browser =3D=3D 'phantomjs': >> + return webdriver.PhantomJS() >> + else: >> + msg =3D 'Selenium driver for browser %s is not available' % b= rowser >> + raise RuntimeError(msg) >> + >> +class Wait(WebDriverWait): >> + """ >> + Subclass of WebDriverWait with predetermined timeout and poll >> + frequency. Also deals with a wider variety of exceptions. >> + """ >> + _TIMEOUT =3D 10 >> + _POLL_FREQUENCY =3D 0.5 >> + >> + def __init__(self, driver): >> + super(Wait, self).__init__(driver, self._TIMEOUT, >> self._POLL_FREQUENCY) >> + >> + def until(self, method, message=3D''): >> + """ >> + Calls the method provided with the driver as an argument unti= l the >> + return value is not False. >> + """ >> + >> + end_time =3D time.time() + self._timeout >> + while True: >> + try: >> + value =3D method(self._driver) >> + if value: >> + return value >> + except NoSuchElementException: >> + pass >> + except StaleElementReferenceException: >> + pass >> + >> + time.sleep(self._poll) >> + if time.time() > end_time: >> + break >> + >> + raise TimeoutException(message) >> + >> + def until_not(self, method, message=3D''): >> + """ >> + Calls the method provided with the driver as an argument unti= l the >> + return value is False. >> + """ >> + >> + end_time =3D time.time() + self._timeout >> + while True: >> + try: >> + value =3D method(self._driver) >> + if not value: >> + return value >> + except NoSuchElementException: >> + return True >> + except StaleElementReferenceException: >> + pass >> + >> + time.sleep(self._poll) >> + if time.time() > end_time: >> + break >> + >> + raise TimeoutException(message) >> + >> +class SeleniumTestCase(StaticLiveServerTestCase): >> + """ >> + NB StaticLiveServerTestCase is used as the base test case so that= >> + static files are served correctly in a Selenium test run context;= see >> + >> https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#special= ized-test-case-to-support-live-testing >> + """ >> + >> + @classmethod >> + def setUpClass(cls): >> + """ Create a webdriver driver at the class level """ >> + >> + super(SeleniumTestCase, cls).setUpClass() >> + >> + # instantiate the Selenium webdriver once for all the test me= thods >> + # in this test case >> + cls.driver =3D create_selenium_driver() >> + cls.driver.maximize_window() >> + >> + @classmethod >> + def tearDownClass(cls): >> + """ Clean up webdriver driver """ >> + >> + cls.driver.quit() >> + super(SeleniumTestCase, cls).tearDownClass() >> + >> + def get(self, url): >> + """ >> + Selenium requires absolute URLs, so convert Django URLs retur= ned >> + by resolve() or similar to absolute ones and get using the >> + webdriver instance. >> + >> + url: a relative URL >> + """ >> + abs_url =3D '%s%s' % (self.live_server_url, url) >> + self.driver.get(abs_url) >> + >> + def find(self, selector): >> + """ Find single element by CSS selector """ >> + return self.driver.find_element_by_css_selector(selector) >> + >> + def find_all(self, selector): >> + """ Find all elements matching CSS selector """ >> + return self.driver.find_elements_by_css_selector(selector) >> + >> + def focused_element(self): >> + """ Return the element which currently has focus on the page = """ >> + return self.driver.switch_to.active_element >> + >> + def wait_until_present(self, selector): >> + """ Wait until element matching CSS selector is on the page "= "" >> + is_present =3D lambda driver: self.find(selector) >> + msg =3D 'An element matching "%s" should be on the page' % se= lector >> + element =3D Wait(self.driver).until(is_present, msg) >> + return element >> + >> + def wait_until_visible(self, selector): >> + """ Wait until element matching CSS selector is visible on th= e >> page """ >> + is_visible =3D lambda driver: self.find(selector).is_displaye= d() >> + msg =3D 'An element matching "%s" should be visible' % select= or >> + Wait(self.driver).until(is_visible, msg) >> + return self.find(selector) >> + >> + def wait_until_focused(self, selector): >> + """ Wait until element matching CSS selector has focus """ >> + is_focused =3D \ >> + lambda driver: self.find(selector) =3D=3D self.focused_el= ement() >> + msg =3D 'An element matching "%s" should be focused' % select= or >> + Wait(self.driver).until(is_focused, msg) >> + return self.find(selector) >> + >> + def enter_text(self, selector, value): >> + """ Insert text into element matching selector """ >> + # note that keyup events don't occur until the element is cli= cked >> + # (in the case of , for example), so >> simulate >> + # user clicking the element before inserting text into it >> + field =3D self.click(selector) >> + >> + field.send_keys(value) >> + return field >> + >> + def click(self, selector): >> + """ Click on element which matches CSS selector """ >> + element =3D self.wait_until_visible(selector) >> + element.click() >> + return element >> + >> + def get_page_source(self): >> + """ Get raw HTML for the current page """ >> + return self.driver.page_source >> -- >> 2.1.4 >> >> >=20 >=20 --KgiimtL3ICmH0UcNJDaE9d9P0WULOlJWd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJXh7YEAAoJEGJqcE9h3glgVr8P/3O74ZnO3L4GLQ17+vDlK8Zk ryCMZbqnBCQ5Uoq/9SVkL4KfOfQg7l1ZWzII88itlqNRbjmR4eOy5/ukVZ+Bh462 ogvVo7w0HHLRgwmZaBeYS2/NXWWj4BEk29QqspJfOOipfp1T9Hk8d7sgsITIO9Gd IEYwXSc8xiQED6OQth4+wwE0bZpv776CIH6YbfLW66scG05lXtYx1HbGKc1DJJra SYUkZYSzc/lo6DiV+l+b2qsoNtjIFYRjJPKxXJ6dRsgl0hU+s7Gzp0IJi/t95hIh sU9rG8wA8yYZQrmCzETmUWD6MIrwxOXc52BBoJArX2TuXskA44B3OicoqjkUIPcG WjFUhnYGJt52tmm56oDzU7rvxzuhvmxxwfdOcBRK06VAfMxLwaIv4NvmFyqKTYgS jSt20xSQofPwHjVDsmo+SysuhatKmYJPdR6tjuck9Z+BP1zXOCGUOnkiw0NkOH+F h61kmFGVgbVxRdyC+eLj6aT46FWWydtQcphlnN3oeRV5Ac4Rs9WDoVN3tCgCEjFJ y1CZ2IGJZ0gYov3dn9ArkfTnMriZiuaOzVjPkbhWCZqCBtKrX8NWyHFh1rQQYKVH LH/NkosEF99VYuz7yW1yyf89zUeMfWml259VYpzdn9AyPVfpSlcf9hDVN43YS954 SzncIDKwtsWSP/PZDbro =5b6N -----END PGP SIGNATURE----- --KgiimtL3ICmH0UcNJDaE9d9P0WULOlJWd--