UNPKG

3.88 kBMarkdownView Raw
1* ["\_\_\_" should have the text "\_\_\_"]("\_\_\_"-should-have-the-text-"\_\_\_")
2 * [regex](regex)
3 * [execution](execution)
4 * [with a span](with-a-span)
5 * [with an input](with-an-input)
6 * [and a "should" expectation](and-a-"should"-expectation)
7 * [and a "should not" expectation](and-a-"should-not"-expectation)
8 * [timing](timing)
9# "\_\_\_" should have the text "\_\_\_"
10## regex
11 regex should match 'the "Test Field" should...'
12
13```
14verifyStepMatch('the "Test Field" should contain the text "Text String"');
15```
16
17
18 regex should match 'the "Test Field" should not...'
19
20```
21verifyStepMatch('the "Test Field" should not contain the text "Text String"');
22```
23
24
25 regex should match '"Test Field" should...'
26
27```
28verifyStepMatch('"Test Field" should contain the text "Text String"');
29```
30
31
32 regex should match '..."Test Field" should contain...'
33
34```
35verifyStepMatch('the "Test Field" should contain the text "Text String"');
36```
37
38
39 regex should match '..."Test Field" should have...'
40
41```
42verifyStepMatch('the "Test Field" should have the text "Text String"');
43```
44
45
46 regex should capture the element name, element type, expectation, and text string
47
48```
49verifyStepCaptures('the "Test" field should contain the text "Text String"', 'Test', ' field', 'should', 'Text String');
50```
51
52
53 regex should capture the element name, text string, and a blank string if no element type is provided
54
55```
56verifyStepCaptures('the "Test Field" should contain the text "Text String"', 'Test Field', '', 'should', 'Text String');
57```
58
59
60 regex should not capture "the" or "contain"
61
62```
63verifyStepDoesNotCapture('the "Test Field" should contain the text "Text String"', 'the', 'contain');
64```
65
66
67## execution
68### with a span
69 with a span should succeed if the element contains the expected text
70
71```
72return executeStep('the "Test Span" should contain the text "Span Text"', function() {
73 expect(currentStepResult.status).to.equal(Cucumber.Status.PASSED);
74});
75```
76
77
78 with a span should fail if the element does not contain the expected text
79
80```
81return executeStep('the "Test Span" should contain the text "Fake Text"', function() {
82 expect(currentStepResult.status).to.equal(Cucumber.Status.FAILED);
83});
84```
85
86
87### with an input
88#### and a "should" expectation
89 and a "should" expectation should succeed if the element contains the expected text
90
91```
92element(By.css('input')).sendKeys("Input Text");
93return executeStep('the "Test Input" should contain the text "Input Text"', function() {
94 expect(currentStepResult.status).to.equal(Cucumber.Status.PASSED);
95});
96```
97
98
99 and a "should" expectation should fail if the element does not contain the expected text
100
101```
102return executeStep('the "Test Input" should contain the text "Input Text"', function() {
103 expect(currentStepResult.status).to.equal(Cucumber.Status.FAILED);
104});
105```
106
107
108#### and a "should not" expectation
109 and a "should not" expectation should fail if the element contains the expected text
110
111```
112element(By.css('input')).sendKeys("Input Text");
113return executeStep('the "Test Input" should not contain the text "Input Text"', function() {
114 expect(currentStepResult.status).to.equal(Cucumber.Status.FAILED);
115});
116```
117
118
119 and a "should not" expectation should fail if the element does not contain the expected text
120
121```
122return executeStep('the "Test Input" should not contain the text "Input Text"', function() {
123 expect(currentStepResult.status).to.equal(Cucumber.Status.PASSED);
124});
125```
126
127
128## timing
129 timing should wait for the element to be present before verifying
130
131```
132return browser.driver.executeScript("setTimeout( function() { $('body').append('<span id=\"testSpan\">Span Text</span>'); }, 200 )").then(() => {
133 return executeStep('the "Test Span" should contain the text "Span Text"', function() {
134 expect(currentStepResult.status).to.equal(Cucumber.Status.PASSED);
135 });
136});
137```