Skip to content

Commit d2be52c

Browse files
elukoyanovVorobeyko
authored andcommitted
fix: TestCafe grabAttributeFrom method not works (#2064)
* fix: testcafe grabAttributeFrom * test: make skippable tests use mocha's skip * fix: TestCafe.grabValueFrom * build: add eslintignore for test output * test: unskip working TestCafe tests * test: remove skip form Nightmare tests * tests: skip testcafe webapi tests * tests: fix skips
1 parent 76ff7de commit d2be52c

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/data/output

lib/helper/TestCafe.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,16 @@ class TestCafe extends Helper {
794794
async grabAttributeFrom(locator, attr) {
795795
const sel = await findElements.call(this, this.context, locator);
796796
assertElementExists(sel);
797-
return (await sel.nth(0)).value;
797+
return (await sel.nth(0)).getAttribute(attr);
798798
}
799799

800800
/**
801801
* {{> grabValueFrom }}
802802
*/
803803
async grabValueFrom(locator) {
804-
return this.grabAttributeFrom(locator, 'value');
804+
const sel = await findElements.call(this, this.context, locator);
805+
assertElementExists(sel);
806+
return (await sel.nth(0)).value;
805807
}
806808

807809
/**

test/helper/webapi.js

+50-53
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports.tests = function () {
5252
describe('#waitInUrl, #waitUrlEquals', () => {
5353
it('should wait part of the URL to match the expected', async () => {
5454
if (isHelper('Nightmare')) return;
55+
5556
try {
5657
await I.amOnPage('/info');
5758
await I.waitInUrl('/info');
@@ -63,6 +64,7 @@ module.exports.tests = function () {
6364

6465
it('should wait for the entire URL to match the expected', async () => {
6566
if (isHelper('Nightmare')) return;
67+
6668
try {
6769
await I.amOnPage('/info');
6870
await I.waitUrlEquals('/info');
@@ -306,6 +308,8 @@ module.exports.tests = function () {
306308
// testcafe always says "xpath is not defined"
307309
// const el = Selector(context).find(elementByXPath(Locator.checkable.byText(xpathLocator.literal(field))).with({ boundTestRun: this.t })).with({ boundTestRun: this.t });
308310
it.skip('should check option by context', async () => {
311+
if (isHelper('TestCafe')) this.skip();
312+
309313
await I.amOnPage('/form/example1');
310314
await I.checkOption('Remember me next time', '.rememberMe');
311315
await I.click('Login');
@@ -358,8 +362,8 @@ module.exports.tests = function () {
358362
});
359363

360364
// Could not get multiselect to work with testcafe
361-
it('should select multiple options', async () => {
362-
if (isHelper('TestCafe')) return;
365+
it('should select multiple options', async function () {
366+
if (isHelper('TestCafe')) this.skip();
363367

364368
await I.amOnPage('/form/select_multiple');
365369
await I.selectOption('What do you like the most?', ['Play Video Games', 'Have Sex']);
@@ -384,16 +388,18 @@ module.exports.tests = function () {
384388
});
385389

386390

387-
it('should return value from sync script in iframe', async () => {
388-
if (isHelper('TestCafe') || isHelper('Nightmare')) return; // TODO Not yet implemented
391+
it('should return value from sync script in iframe', async function () {
392+
if (isHelper('Nightmare')) return; // TODO Not yet implemented
393+
if (isHelper('TestCafe')) this.skip(); // TODO Not yet implemented
394+
389395
await I.amOnPage('/iframe');
390396
await I.switchTo('iframe');
391397
const val = await I.executeScript(() => document.getElementsByTagName('h1')[0].innerText);
392398
assert.equal(val, 'Information');
393399
});
394400

395-
it('should execute async script', async () => {
396-
if (isHelper('TestCafe')) return; // TODO Not yet implemented
401+
it('should execute async script', async function () {
402+
if (isHelper('TestCafe')) this.skip(); // TODO Not yet implemented
397403

398404
await I.amOnPage('/');
399405
const val = await I.executeAsyncScript((val, done) => {
@@ -572,8 +578,8 @@ module.exports.tests = function () {
572578
assert.equal(vals[2], 'Third');
573579
});
574580

575-
it('should grab html from page', async () => {
576-
if (isHelper('TestCafe')) return;
581+
it('should grab html from page', async function () {
582+
if (isHelper('TestCafe')) this.skip();
577583

578584
await I.amOnPage('/info');
579585
const val = await I.grabHTMLFrom('#grab-multiple');
@@ -605,7 +611,6 @@ module.exports.tests = function () {
605611
});
606612

607613
it('should grab attribute from element', async () => {
608-
if (isHelper('TestCafe')) return;
609614
await I.amOnPage('/search');
610615
const val = await I.grabAttributeFrom({
611616
css: 'form',
@@ -614,8 +619,6 @@ module.exports.tests = function () {
614619
});
615620

616621
it('should grab custom attribute from element', async () => {
617-
if (isHelper('TestCafe')) return;
618-
619622
await I.amOnPage('/form/example4');
620623
const val = await I.grabAttributeFrom({
621624
css: '.navbar-toggle',
@@ -625,8 +628,8 @@ module.exports.tests = function () {
625628
});
626629

627630
describe('page title : #seeTitle, #dontSeeTitle, #grabTitle', () => {
628-
it('should check page title', async () => {
629-
if (isHelper('TestCafe')) return;
631+
it('should check page title', async function () {
632+
if (isHelper('TestCafe')) this.skip();
630633

631634
await I.amOnPage('/');
632635
await I.seeInTitle('TestEd Beta 2.0');
@@ -635,8 +638,8 @@ module.exports.tests = function () {
635638
await I.dontSeeInTitle('TestEd Beta 2.0');
636639
});
637640

638-
it('should grab page title', async () => {
639-
if (isHelper('TestCafe')) return;
641+
it('should grab page title', async function () {
642+
if (isHelper('TestCafe')) this.skip();
640643

641644
await I.amOnPage('/');
642645
const val = await I.grabTitle();
@@ -657,6 +660,7 @@ module.exports.tests = function () {
657660

658661
it('should upload file located by label', async () => {
659662
if (isHelper('Nightmare')) return;
663+
660664
await I.amOnPage('/form/file');
661665
await I.attachFile('Avatar', 'app/avatar.jpg');
662666
await I.click('Submit');
@@ -672,17 +676,13 @@ module.exports.tests = function () {
672676
});
673677

674678
it('should create a screenshot file in output dir', async () => {
675-
if (isHelper('TestCafe')) return;
676-
677679
const sec = (new Date()).getUTCMilliseconds();
678680
await I.amOnPage('/');
679681
await I.saveScreenshot(`screenshot_${sec}.png`);
680682
assert.ok(fileExists(path.join(global.output_dir, `screenshot_${sec}.png`)), null, 'file does not exists');
681683
});
682684

683685
it('should create a full page screenshot file in output dir', async () => {
684-
if (isHelper('TestCafe')) return;
685-
686686
const sec = (new Date()).getUTCMilliseconds();
687687
await I.amOnPage('/');
688688
await I.saveScreenshot(`screenshot_full_${+sec}.png`, true);
@@ -750,8 +750,8 @@ module.exports.tests = function () {
750750
await I.see('Dynamic text');
751751
});
752752

753-
it('should fail if no context', async () => {
754-
if (isHelper('TestCafe')) return;
753+
it('should fail if no context', async function () {
754+
if (isHelper('TestCafe')) this.skip();
755755

756756
let failed = false;
757757
await I.amOnPage('/dynamic');
@@ -764,8 +764,8 @@ module.exports.tests = function () {
764764
assert.ok(failed);
765765
});
766766

767-
it('should fail if text doesn\'t contain', async () => {
768-
if (isHelper('TestCafe')) return;
767+
it('should fail if text doesn\'t contain', async function () {
768+
if (isHelper('TestCafe')) this.skip();
769769

770770
let failed = false;
771771
await I.amOnPage('/dynamic');
@@ -777,8 +777,8 @@ module.exports.tests = function () {
777777
assert.ok(failed);
778778
});
779779

780-
it('should fail if text is not in element', async () => {
781-
if (isHelper('TestCafe')) return;
780+
it('should fail if text is not in element', async function () {
781+
if (isHelper('TestCafe')) this.skip();
782782

783783
let failed = false;
784784
await I.amOnPage('/dynamic');
@@ -791,8 +791,6 @@ module.exports.tests = function () {
791791
});
792792

793793
it('should wait for text after timeout', async () => {
794-
if (isHelper('TestCafe')) return;
795-
796794
await I.amOnPage('/timeout');
797795
await I.dontSee('Timeout text');
798796
await I.waitForText('Timeout text', 31, '#text');
@@ -910,8 +908,8 @@ module.exports.tests = function () {
910908
});
911909

912910
describe('#waitForDetached', () => {
913-
it('should throw an error if the element still exists in DOM', async () => {
914-
if (isHelper('TestCafe')) return;
911+
it('should throw an error if the element still exists in DOM', async function () {
912+
if (isHelper('TestCafe')) this.skip();
915913

916914
await I.amOnPage('/form/wait_detached');
917915
await I.see('Step One Button');
@@ -925,8 +923,8 @@ module.exports.tests = function () {
925923
}
926924
});
927925

928-
it('should throw an error if the element still exists in DOM by XPath', async () => {
929-
if (isHelper('TestCafe')) return;
926+
it('should throw an error if the element still exists in DOM by XPath', async function () {
927+
if (isHelper('TestCafe')) this.skip();
930928

931929
await I.amOnPage('/form/wait_detached');
932930
await I.see('Step One Button');
@@ -940,8 +938,8 @@ module.exports.tests = function () {
940938
}
941939
});
942940

943-
it('should wait for element to be removed from DOM', async () => {
944-
if (isHelper('TestCafe')) return;
941+
it('should wait for element to be removed from DOM', async function () {
942+
if (isHelper('TestCafe')) this.skip();
945943

946944
await I.amOnPage('/form/wait_detached');
947945
await I.see('Step Two Button');
@@ -950,8 +948,8 @@ module.exports.tests = function () {
950948
await I.dontSeeElementInDOM('#step_2');
951949
});
952950

953-
it('should wait for element to be removed from DOM by XPath', async () => {
954-
if (isHelper('TestCafe')) return;
951+
it('should wait for element to be removed from DOM by XPath', async function () {
952+
if (isHelper('TestCafe')) this.skip();
955953

956954
await I.amOnPage('/form/wait_detached');
957955
await I.seeElement('//div[@id="step_2"]');
@@ -1010,8 +1008,6 @@ module.exports.tests = function () {
10101008
});
10111009

10121010
it('should execute within block 2', async () => {
1013-
if (isHelper('TestCafe')) return;
1014-
10151011
await I.amOnPage('/form/example4');
10161012
await I.fillField('Hasło', '12345');
10171013
await I._withinBegin({ xpath: '//div[@class="form-group"][2]' });
@@ -1025,8 +1021,8 @@ module.exports.tests = function () {
10251021
assert.equal(input, '12345');
10261022
});
10271023

1028-
it('within should respect context in see', async () => {
1029-
if (isHelper('TestCafe')) return;
1024+
it('within should respect context in see', async function () {
1025+
if (isHelper('TestCafe')) this.skip();
10301026

10311027
await I.amOnPage('/form/example4');
10321028
await I.see('Rejestracja', 'fieldset');
@@ -1047,6 +1043,7 @@ module.exports.tests = function () {
10471043

10481044
it('within should respect context in see when using nested frames', async function () {
10491045
if (isHelper('TestCafe')) this.skip();
1046+
10501047
await I.amOnPage('/iframe_nested');
10511048
await I._withinBegin({
10521049
frame: ['#wrapperId', '[name=content]'],
@@ -1073,9 +1070,9 @@ module.exports.tests = function () {
10731070
});
10741071

10751072
describe('scroll: #scrollTo, #scrollPageToTop, #scrollPageToBottom', () => {
1076-
it('should scroll inside an iframe', async () => {
1073+
it('should scroll inside an iframe', async function () {
10771074
if (isHelper('Nightmare')) return;
1078-
if (isHelper('TestCafe')) return;
1075+
if (isHelper('TestCafe')) this.skip();
10791076

10801077
await I.amOnPage('/iframe');
10811078
await I.resizeWindow(500, 700);
@@ -1135,9 +1132,9 @@ module.exports.tests = function () {
11351132
});
11361133

11371134
describe('#grabCssPropertyFrom', () => {
1138-
it('should grab css property for given element', async () => {
1135+
it('should grab css property for given element', async function () {
11391136
if (isHelper('Nightmare')) return;
1140-
if (isHelper('TestCafe')) return;
1137+
if (isHelper('TestCafe')) this.skip();
11411138

11421139
await I.amOnPage('/form/doubleclick');
11431140
const css = await I.grabCssPropertyFrom('#block', 'height');
@@ -1155,9 +1152,9 @@ module.exports.tests = function () {
11551152
});
11561153

11571154
describe('#seeAttributesOnElements', () => {
1158-
it('should check attributes values for given element', async () => {
1155+
it('should check attributes values for given element', async function () {
11591156
if (isHelper('Nightmare')) return;
1160-
if (isHelper('TestCafe')) return;
1157+
if (isHelper('TestCafe')) this.skip();
11611158

11621159
try {
11631160
await I.amOnPage('/info');
@@ -1177,9 +1174,9 @@ module.exports.tests = function () {
11771174
}
11781175
});
11791176

1180-
it('should check attributes values for several elements', async () => {
1177+
it('should check attributes values for several elements', async function () {
11811178
if (isHelper('Nightmare')) return;
1182-
if (isHelper('TestCafe')) return;
1179+
if (isHelper('TestCafe')) this.skip();
11831180

11841181
try {
11851182
await I.amOnPage('/');
@@ -1202,9 +1199,9 @@ module.exports.tests = function () {
12021199
});
12031200

12041201
describe('#seeCssPropertiesOnElements', () => {
1205-
it('should check css property for given element', async () => {
1202+
it('should check css property for given element', async function () {
12061203
if (isHelper('Nightmare')) return;
1207-
if (isHelper('TestCafe')) return;
1204+
if (isHelper('TestCafe')) this.skip();
12081205

12091206
try {
12101207
await I.amOnPage('/info');
@@ -1225,9 +1222,9 @@ module.exports.tests = function () {
12251222
});
12261223

12271224

1228-
it('should check css property for several elements', async () => {
1225+
it('should check css property for several elements', async function () {
12291226
if (isHelper('Nightmare')) return;
1230-
if (isHelper('TestCafe')) return;
1227+
if (isHelper('TestCafe')) this.skip();
12311228

12321229
try {
12331230
await I.amOnPage('/');
@@ -1252,9 +1249,9 @@ module.exports.tests = function () {
12521249
}
12531250
});
12541251

1255-
it('should normalize css color properties for given element', async () => {
1252+
it('should normalize css color properties for given element', async function () {
12561253
if (isHelper('Nightmare')) return;
1257-
if (isHelper('TestCafe')) return;
1254+
if (isHelper('TestCafe')) this.skip();
12581255

12591256
await I.amOnPage('/form/css_colors');
12601257
await I.seeCssPropertiesOnElements('#namedColor', {

0 commit comments

Comments
 (0)