MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / assertTextIs

Function assertTextIs

javascript/atoms/test/text_util.js:55–90  ·  view source on GitHub ↗

* Verifies that the visible text for the test DOM structure. * @param {!Object} assert The QUnit assert object. * @param {string} testName The name of the current test. * @param {!Element} element The element to check the text of. * @param {...string} var_args Variadic args for the expected line

(assert, testName, element, var_args)

Source from the content-addressed store, hash-verified

53 * of visible text.
54 */
55function assertTextIs(assert, testName, element, var_args) {
56 if (!element.parentNode ||
57 // IE sets the parentNode of unattached elements to a document fragment.
58 element.parentNode.nodeType != goog.dom.NodeType.ELEMENT) {
59 var testContainer = getTestContainer();
60 testContainer.appendChild(createTestDom(element));
61 }
62
63 var expected = goog.array.slice(arguments, 3).join('\n');
64 var actual = bot.dom.getVisibleText(element);
65
66 assert.strictEqual(actual, expected,
67 'Expected: ' + escapeText(expected) +
68 '\n but was: ' + escapeText(actual) +
69 '\n raw html:\n' + element.innerHTML +
70 '\n------\n');
71
72 function createTestDom(element) {
73 return goog.dom.createDom('div', {'style': 'width: 25em;'},
74 goog.dom.createDom('div',
75 {'style': [
76 'margin: 0 0.5em;',
77 'padding: 0;',
78 'font-style: italic;',
79 'color: gray;'
80 ].join('')},
81 testName),
82 goog.dom.createDom('div', {
83 'style': 'margin-bottom: 0.5em'
84 }, element));
85 }
86
87 function escapeText(text) {
88 return text.replace(/\n/g, '\\n');//.replace(/\s/g, '\\s');
89 }
90}

Callers

nothing calls this directly

Calls 3

getTestContainerFunction · 0.85
createTestDomFunction · 0.85
escapeTextFunction · 0.85

Tested by

no test coverage detected