forked from cobrateam/splinter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
element_does_not_exist.py
48 lines (35 loc) · 2.18 KB
/
element_does_not_exist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
from splinter.exceptions import ElementDoesNotExist
class ElementDoestNotExistTest(object):
def test_element_query_should_raises_when_element_first_doest_exists(self):
with self.assertRaises(ElementDoesNotExist):
self.browser.find_by_css('.element-that-dont-exists').first
def test_element_list_raises_when_element_last_does_not_exists(self):
with self.assertRaises(ElementDoesNotExist):
self.browser.find_by_css('.element-that-dont-exists').last
def test_element_list_raises_when_element_does_not_exists(self):
with self.assertRaises(ElementDoesNotExist):
self.browser.find_by_css('.element-that-dont-exists')[2]
def test_element_list_contains_right_information_and_raises_right_exception(self):
"element list contains right information about query and raises nice exception message"
with self.assertRaises(ElementDoesNotExist) as cm:
element_list = self.browser.find_by_css('.element-that-dont-exists')
self.assertEqual('css', element_list.find_by)
self.assertEqual('.element-that-dont-exists', element_list.query)
element_list.first
expected_message = 'no elements could be found with css ".element-that-dont-exists"'
e = cm.exception
self.assertEqual(expected_message, e.args[0])
def test_element_list_raises_when_element_first_doesnt_exists_in_element_context(self):
"element list raises exception with right information in element context"
with self.assertRaises(ElementDoesNotExist) as cm:
element_list = self.browser.find_by_css("#inside").find_by_css('.inner-element-that-dont-exists')
self.assertEqual('css', element_list.find_by)
self.assertEqual('.inner-element-that-dont-exists', element_list.query)
element_list.first
expected_message = 'no elements could be found with css ".inner-element-that-dont-exists"'
e = cm.exception
self.assertEqual(expected_message, e.args[0])