• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
7import common
8from autotest_lib.client.bin import test
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.common_lib.cros import chromedriver
11from autotest_lib.client.cros import httpd
12
13
14class desktopui_SetFieldsWithChromeDriver(test.test):
15    """Test setting a text field via Chrome Driver."""
16    version = 1
17
18    def initialize(self):
19        """Initialize the test.
20        """
21        super(desktopui_SetFieldsWithChromeDriver, self).initialize()
22
23        self._test_url = 'http://localhost:8000/hello.html'
24        self._expected_title = 'Hello World'
25        self._domain = 'localhost'
26        self._element_id = '123'
27        self._text = 'Hello World'
28        self._testServer = httpd.HTTPListener(8000, docroot=self.bindir)
29        self._testServer.run()
30
31
32    def cleanup(self):
33        """Clean up the test environment, e.g., stop local http server."""
34        if hasattr(self, '_testServer'):
35            self._testServer.stop()
36        super(desktopui_SetFieldsWithChromeDriver, self).cleanup()
37
38
39    def run_once(self):
40        """Run the test code."""
41        with chromedriver.chromedriver() as chromedriver_instance:
42            driver = chromedriver_instance.driver
43            driver.get(self._test_url)
44            logging.info('Expected tab title: %s. Got: %s',
45                         self._expected_title, driver.title)
46            if driver.title != self._expected_title:
47                raise error.TestError('Getting title failed, got title: %s'
48                                      % driver.title)
49
50            element = driver.find_element_by_id(self._element_id)
51            element.clear()
52            element.send_keys(self._text)
53            entered_text = element.get_attribute("value")
54            if entered_text != self._text:
55                raise error.TestError('Value of text box %s, expected %s' %
56                                      (self._text, entered_text))
57
58