Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Unified Diff: chrome/test/webdriver/webdriver_remote_tests.py

Issue 3643002: Implemnts the commands in webdriver to preform searching of elements on a page. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix for windows build Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/webdriver/server.cc ('k') | third_party/webdriver/py/selenium/remote/webdriver/WebDriver.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/webdriver_remote_tests.py
diff --git a/chrome/test/webdriver/webdriver_remote_tests.py b/chrome/test/webdriver/webdriver_remote_tests.py
index 43371c7ad021934fc23596f8c96e94bdbe8dd1ff..1ff2b4461b7d035b49e34129fc302c06303605b1 100644
--- a/chrome/test/webdriver/webdriver_remote_tests.py
+++ b/chrome/test/webdriver/webdriver_remote_tests.py
@@ -18,8 +18,10 @@ import time
import types
import unittest
import urllib2
-from selenium.remote.webdriver import WebDriver
from selenium.common.exceptions import ErrorInResponseException
+from selenium.common.exceptions import NoSuchElementException
+from selenium.remote.webdriver import WebDriver
+from selenium.remote.webdriver.webelement import WebElement
from urlparse import urlparse
@@ -42,6 +44,19 @@ if not WEBDRIVER_SERVER_URL:
WEBDRIVER_SERVER_URL = 'http://localhost:%d' % WEBDRIVER_PORT
class RemoteWebDriverTest(unittest.TestCase):
+ SEARCH = "http://www.google.com/webhp?hl=en"
+ NEWS = "http://www.google.com/news?hl=en"
+
+ """Verifies that navigation to a specific page is correct by asserting on the
+ the reported URL. The function will not work with pages that redirect."""
+ def navigate(self, url):
+ self.driver.get(url)
+ self.assertURL(url)
+
+ def assertURL(self, url):
+ u = self.driver.get_current_url()
+ self.assertEqual(u, url)
+
"""A new instance of chrome driver is started for every test case"""
def setUp(self):
global WEBDRIVER_SERVER_URL
@@ -81,6 +96,50 @@ class RemoteWebDriverTest(unittest.TestCase):
search = string.lower(search)
self.assertNotEqual(-1, string.find(text, search))
+class TestFindElement(RemoteWebDriverTest):
+ def testFindByName(self):
+ navigate(SEARCH)
+ # Find the Google search button.
+ q = self.driver.find_element_by_name("q")
+ self.assertTrue(isinstance(q, WebElement))
+ # Trying looking for an element not on the page.
+ self.assertRaises(NoSuchElementException,
+ self.driver.find_elment_by_name, "q2")
+ # Try to find the Google search button using the multiple find method.
+ q = self.driver.find_elements_by_name("q")
+ self.assertTrue(isinstance(q, list))
+ self.assertTrue(len(q), 1)
+ self.assertTrue(isinstance(q[0], WebElement))
+ # Try finding something not on page, with multiple find an empty array
+ # should return and no exception thrown.
+ q = self.driver.find_elements_by_name("q2")
+ assertTrue(q == [])
+ # Find a hidden element on the page
+ q = self.driver.find_element_by_name("oq")
+ self.assertTrue(isinstance(q, WebElement))
+
+ def testFindElementById(self):
+ navigate(SEARCH)
+ # Find the padding for the logo near the search bar.
+ elem = self.driver.find_element_by_id("logocont")
+ self.assertTrue(isinstance(elem, WebElement))
+ # Look for an ID not there.
+ self.assertRaises(NoSuchElementException,
+ self.driver.find_element_by_id, "logocont")
+
+ def testFindElementById0WithTimeout(self):
+ self.set_implicit_wait(0)
+ navigate(SEARCH)
+ # Find the padding for the logo near the search bar.
+ elem = self.driver.find_element_by_id("logocont")
+ self.assertTrue(isinstance(elem, WebElement))
+ self.set_implicit_wait(5000)
+ navigate(SEARCH)
+ # Look for an ID not there.
+ self.assertRaises(NoSuchElementException,
+ self.driver.find_element_by_id, "logocont")
+
+
class TestJavaScriptExecution(RemoteWebDriverTest):
""" Test the execute javascript ability of the remote driver"""
def testNoModification(self):
@@ -120,19 +179,6 @@ class TestJavaScriptExecution(RemoteWebDriverTest):
class TestNavigation(RemoteWebDriverTest):
- SEARCH = "http://www.google.com/webhp?hl=en"
- NEWS = "http://www.google.com/news?hl=en"
-
- """Verifies that navigation to a specific page is correct by asserting on the
- the reported URL. The function will not work with pages that redirect."""
- def navigate(self, url):
- self.driver.get(url)
- self.assertURL(url)
-
- def assertURL(self, url):
- u = self.driver.get_current_url()
- self.assertEqual(u, url)
-
def testNavigateToURL(self):
# No redirects are allowed on the google home page.
self.navigate(self.SEARCH)
« no previous file with comments | « chrome/test/webdriver/server.cc ('k') | third_party/webdriver/py/selenium/remote/webdriver/WebDriver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698