testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

My test gives error: await is a reserved word for await element.with({visibilityCheck: true })();

Open gpawel opened this issue 7 years ago • 3 comments

What is your Test Scenario?

I am creating a page object from a test: var formTools = await designer.openToolsList();

What is the Current behavior?

computer:~/workspace/project$ testcafe chrome js/CaffeTest.js await element.with({visibilityCheck: true })(); or //await t.expect(element.visible).ok(); returns error message: await is a reserved word.

ERROR Cannot prepare tests due to an error.

SyntaxError: /home/pavel/workspace/project/js/page/FormToolList.js: await is a reserved word (13:8)
  11 |     constructor() {
  12 |         const element = Selector(powerToolsBoxOpened);
> 13 |         await element.with({visibilityCheck: true })();
     |         ^
  14 |         //await t.expect(element.visible).ok();
  15 |     }
  16 | 
    at ESNextTestFileCompiler._compileCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/formats/es-next/compiler.js:57:32)
    at Object..js (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/formats/es-next/compiler.js:65:50)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:88:63)
    at Object.<anonymous> (/home/pavel/workspace/project/js/page/Designer.js:3:1)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:92:25)
    at Object.<anonymous> (/home/pavel/workspace/project/js/page/FormsNavigator.js:2:1)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:92:25)
    at Object.<anonymous> (/home/pavel/workspace/project/js/CaffeTest.js:3:1)
    at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
    at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)

Type "testcafe -h" for help.
computer:~/workspace/project$ ^C

What is the Expected behavior?

No error is expected. Obviosly I am doing something wrong but don't understand what exactly.

What is your web application and your TestCafe test code?

Here is the model:

import { Selector, t } from 'testcafe';
import { ClientFunction } from 'testcafe';

const powerToolsBoxOpened = "section[class='powerFormsTools open']";
const actionTools = powerToolsBoxOpened + " span[class='toolmenu ToolsList1']";
const actionToolsOpened = powerToolsBoxOpened + " span[class='toolmenu ToolsList1 open']";
const inputTools = powerToolsBoxOpened + " span[class='toolmenu ToolsList4']";
const inputToolsOpened = powerToolsBoxOpened + " span[class='toolmenu ToolsList4 open']";

export default class FormToolList {
    constructor() {
        const element = Selector(powerToolsBoxOpened);
        await element.with({visibilityCheck: true })();
        //t.expect(await .visible).ok();
    }

}

Your website URL (or attach your complete example):

Your complete test code (or attach your test files):
 test("Using Forms class", async t => {
	console.log("test two");
	await forms.openFormDrafts();
	var designer = await forms.openFormDesigner();
	await designer.startBuildForm();
	var formTools = await designer.openToolsList();	
	await formTools.openActionsList();
	await formTools.openInputsList();	
});

in designer object:
async openToolsList() {		
		await t.click(insertNewElement);
		return await FormToolList();
	}
Your complete configuration file (if any):

Your complete test report:

Screenshots:

Your Environment details:

  • testcafe version: 1.5.0
  • node.js version: v8.10.0
  • command-line arguments: testcafe chrome js/CaffeTest.js
  • browser name and version: chrome Version 77.0.3865.90 (Official Build) (64-bit)
  • platform and version: Linux Ubuntu 18.04.1

gpawel avatar Sep 29 '19 19:09 gpawel

Note: when the FormListTool constructor is written as: constructor() { const element = Selector(powerToolsBoxOpened); //await element.with({visibilityCheck: true })(); t.expect(await element.visible).ok(); } The test runs but returns the following message:

 ✖ Using Forms class

   1) A call to an async function is not awaited. Use the "await" keyword before actions, assertions or
      chains of them to ensure that they run in the right sequence.

      Browser: Chrome 77.0.3865 / Linux 0.0.0

          9 |
         10 |export default class FormToolList {
         11 |    constructor() {
         12 |        const element = Selector(powerToolsBoxOpened);
         13 |        //await element.with({visibilityCheck: true })();
       > 14 |        t.expect(element.visible).ok();
         15 |    }
         16 |
         17 |    async openActionsList() {
         18 |        var actionListSelector = await Selector(actionToolsOpened);
         19 |        if (await actionListSelector.exist) return;

         at new ok (/home/pavel/workspace/powerfulforms/js/page/FormToolList.js:14:35)
         at <anonymous> (/home/pavel/workspace/powerfulforms/js/page/Designer.js:24:16)



 1/1 failed (11s)


gpawel avatar Sep 29 '19 19:09 gpawel

The javascript syntax you are using has certain issues. await is valid only in the async function and a class constructor may not be an async method. Therefore, the constructor is not the place where you can execute actions or assertions.

LavrovArtem avatar Sep 30 '19 13:09 LavrovArtem

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

lock[bot] avatar Oct 10 '19 14:10 lock[bot]