[Pkg-giraffe-discuss] autopkgtest in kopano-webapp

Guido Günther agx at sigxcpu.org
Wed Dec 26 11:31:45 GMT 2018


Hi,
On Tue, Dec 25, 2018 at 07:11:59PM +0100, Carsten Schoenert wrote:
> Hi,
> 
> I tried to play around with the non working autopkgtest in kopano-webapp.
> 
> In preparation for 3.5.0 I added a missing 'need-root' to the control
> file due the needed database setup. But then you get a warning about
> phantomjs isn't supported any more, you need to work now in headless
> mode. After some searching what's needed to get changed for this I got
> this now working by this change.
> 
> > diff --git a/debian/tests/test_webapp.py b/debian/tests/test_webapp.py
> > index 421369b..b8eb84d 100644
> > --- a/debian/tests/test_webapp.py
> > +++ b/debian/tests/test_webapp.py
> > @@ -10,6 +10,11 @@ from selenium.webdriver.common.keys import Keys
> >  from selenium.webdriver.support.ui import WebDriverWait
> >  from selenium.common.exceptions import TimeoutException, NoSuchElementException
> >  
> > +chrome_options = webdriver.ChromeOptions()
> > +chrome_options.add_argument('--headless')
> > +chrome_options.add_argument('--no-sandbox')
> > +chrome_options.add_argument('--window-size=1120x550')
> > +
> >  URL = os.getenv('WEBAPP_URL', 'http://127.0.0.1/webapp/')
> >  auth_user = os.environ['AUTH_USER']
> >  auth_pass = os.environ['AUTH_PASS']
> > @@ -18,8 +23,9 @@ auth_pass = os.environ['AUTH_PASS']
> >  class TestWebApp(unittest.TestCase):
> >  
> >      def setUp(self):
> > -        self.driver = webdriver.PhantomJS()
> > -        self.driver.set_window_size(1120, 550)
> > +        self.driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver',
> > +                      chrome_options=chrome_options,
> > +                      service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
> >  
> >      def tearDown(self):
> >          self.driver.quit()
> 
> The current implementation can be reduced later a bit for sure, it's
> mostly some dirty C&P for now to get it working. It working ... but now
> we get a Python Traceback due some left over coding issue due changes to
> Python?
> 
> > Processing triggers for systemd (240-1) ...
> > + grep -qs User created.
> > + kopano-admin -c mailtest -p r00tme -e admin at example.com -f Mail test user -a 1
> > + cd debian/tests
> > + export AUTH_USER=mailtest
> > + export AUTH_PASS=r00tme
> > + nosetests
> > E
> > ======================================================================
> > ERROR: test_login (test_webapp.TestWebApp)
> > ----------------------------------------------------------------------
> > Traceback (most recent call last):
> >   File "/tmp/autopkgtest.Loh9WK/build.l9h/src/debian/tests/test_webapp.py", line 53, in test_login
> >     elem = self.find_element_by_('name', 'username')
> >   File "/tmp/autopkgtest.Loh9WK/build.l9h/src/debian/tests/test_webapp.py", line 41, in find_element_by_
> >     return find_element_by_(name)
> > TypeError: 'str' object is not callable
> > -------------------- >> begin captured logging << --------------------
> > selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:46767/session {"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"args": ["--headless", "--no-sandbox", "--window-size=1120x550"], "extensions": []}, "browserName": "chrome", "platformName": "any"}, "firstMatch": [{}]}, "desiredCapabilities": {"goog:chromeOptions": {"args": ["--headless", "--no-sandbox", "--window-size=1120x550"], "extensions": []}, "platform": "ANY", "browserName": "chrome", "version": ""}}
> > urllib3.connectionpool: DEBUG: Starting new HTTP connection (1): 127.0.0.1:46767
> > urllib3.connectionpool: DEBUG: http://127.0.0.1:46767 "POST /session HTTP/1.1" 200 888
> > selenium.webdriver.remote.remote_connection: DEBUG: Finished Request
> > selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:46767/session/2fb50dec4326658d7e9dbc464c4b2cca/url {"url": "http://127.0.0.1/webapp/", "sessionId": "2fb50dec4326658d7e9dbc464c4b2cca"}
> > urllib3.connectionpool: DEBUG: http://127.0.0.1:46767 "POST /session/2fb50dec4326658d7e9dbc464c4b2cca/url HTTP/1.1" 200 72
> > selenium.webdriver.remote.remote_connection: DEBUG: Finished Request
> > selenium.webdriver.remote.remote_connection: DEBUG: GET http://127.0.0.1:46767/session/2fb50dec4326658d7e9dbc464c4b2cca/title {"sessionId": "2fb50dec4326658d7e9dbc464c4b2cca"}
> > urllib3.connectionpool: DEBUG: http://127.0.0.1:46767 "GET /session/2fb50dec4326658d7e9dbc464c4b2cca/title HTTP/1.1" 200 83
> > selenium.webdriver.remote.remote_connection: DEBUG: Finished Request
> > --------------------- >> end captured logging << ---------------------
> > 
> > ----------------------------------------------------------------------
> > Ran 1 test in 3.034s
> > 
> > FAILED (errors=1)
> 
> The problem is here:
> 
> >     def find_element_by_(self, type, name):
> >         try:
> >             find_element_by_ = getattr(self.driver, 'find_element_by_%s', type)
> >             return find_element_by_(name)
> 
> As far I understand 'find_element_by_' should be expanded by 'name' and
> if I change this to
> 
> >             find_element_by_ = getattr(self.driver, 'find_element_by_' + type)
> 
> this is working for 'username' and 'password' but not later for
> preparing and sending an mail.
> 
> > ======================================================================
> > ERROR: test_login (test_webapp.TestWebApp)
> > ----------------------------------------------------------------------
> > Traceback (most recent call last):
> >   File "/tmp/autopkgtest.amx76m/build.wWZ/src/debian/tests/test_webapp.py", line 68, in test_login
> >     element = WebDriverWait(self.driver, 40).until(lambda self: self.find_element_by_("class_name", "icon_createEmailMessage"))
> >   File "/usr/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py", line 71, in until
> >     value = method(self._driver)
> >   File "/tmp/autopkgtest.amx76m/build.wWZ/src/debian/tests/test_webapp.py", line 68, in <lambda>
> >     element = WebDriverWait(self.driver, 40).until(lambda self: self.find_element_by_("class_name", "icon_createEmailMessage"))
> > AttributeError: 'WebDriver' object has no attribute 'find_element_by_'
> 
> Someone has some quick fix I can try? :-)

It seems the lambda is capturing another scope and self is the WebDriver
instead of the test. Can you try:

   t = self
   element = WebDriverWait(self.driver, 40).until(lambda t: t.find_element_by_("class_name", "icon_createEmailMessage"))

Cheers,
 -- Guido



More information about the Pkg-giraffe-discuss mailing list