Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use protractor-sync module with cucumber #82

Open
Vardhan18 opened this issue Mar 26, 2019 · 3 comments
Open

Not able to use protractor-sync module with cucumber #82

Vardhan18 opened this issue Mar 26, 2019 · 3 comments

Comments

@Vardhan18
Copy link

Vardhan18 commented Mar 26, 2019

I am using protractor-sync module with cucumber so that to make the calls synchronously But when I start using the functions of protractor-sync
browserSync.get("https://www.google.com");

Error: Could not find the current asyncblock flow. Please make sure this method is called from an asyncblock context.
Error console:
× Given Navigate to Google Page # Protractor\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173 Error: Could not find the current asyncblock flow. Please make sure this method is called from an asyncblock context. at Object.exec (C:\Cucumber Protractor\node_modules\protractor-sync\dist\exec.js:10:19) at BrowserSync.get (C:\Cucumber Protractor\node_modules\protractor-sync\dist\browser-sync.js:34:23) at World.<anonymous> (C:\Cucumber Protractor\steps\LoginSteps.ts:12:15)

Feature File
`
Feature: Validation test

@CucumberScenario
Scenario: Validate Google Page
Given Navigate to Google Page
`

Steps File:
`
import { Given } from 'cucumber';
import { browserSync } from 'protractor-sync';

Given('Navigate to Google Page',{ timeout: 120 * 1000 }, ()=> {

browserSync.get("https://www.google.com");

});
protractor conf.js
exports.config = {
allScriptsTimeout: 240000,
specs: [
"./features/*.feature",
],
framework: 'custom',
frameworkPath: require.resolve("protractor-cucumber-framework"),
cucumberOpts: {
strict: true,
compiler: 'ts:ts-node/register'

}

};
`
Can we use protractor-sync module along with cucumber ?

@mindywhitsitt
Copy link
Contributor

Hi,

The error you're receiving isn't related to the use of cucumber. Rather, you'll need to call protractor-sync methods within an asyncblock flow. Be sure to import asyncblock at the top:

import * as ab from 'asyncblock';

Then you'll need to create an asyncblock flow and put your code inside it. The example in our readme shows a somewhat more complex way of doing this (note that createTest is creating an asyncblock flow), but I believe you could also do something like:

ab(() => {
  // your code here
});

@Vardhan18
Copy link
Author

Vardhan18 commented Mar 29, 2019

Hi @mindywhitsitt ,

As per your inputs, I have used async block as follows in the code

import { Given,setDefaultTimeout } from 'cucumber';
import { browserSync, configure, elementSync, polledExpect } from 'protractor-sync';
import * as ab from 'asyncblock';
configure({ implicitWaitMs: 500 });
function createTest(fn: Function, errorMsg?: string) {
  return (done: Function) => {
    ab(() => {
      fn();
    }, (err: any) => {
      if (errorMsg) {
        expect(err.message).toEqual(errorMsg);
      } else {
        expect(err && err.stack || err || undefined).toBeUndefined();
      }
      done();
    });
  };
}
setDefaultTimeout(20 * 1000); 
Given('Navigate to Google Page', createTest(() => {
  const googleTranslateUrl = 'https://translate.google.com/'; 
     browserSync.waitForAngularEnabled(false);
    browserSync.get(googleTranslateUrl);   
  
    
}));

Getting following error

× Given Navigate to Google Page # Protractor\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:173
       Error: function timed out, ensure the callback is executed within 20000 milliseconds
           at Timeout._time.default.setTimeout [as _onTimeout] (.\node_modules\cucumber\lib\user_code_runner.js:81:20)
           at ontimeout (timers.js:475:11)
           at tryOnTimeout (timers.js:310:5)
           at Timer.listOnTimeout (timers.js:270:5)

let me know for any information

@mindywhitsitt
Copy link
Contributor

Hm. It appears that function timed out error is coming from cucumber rather than protractor_sync. I'm not familiar with cucumber, so I'm not sure how much help I'll be in getting the two to work together. Is it possible that cucumber is expecting something else to be returned? In that case, maybe something like https://stackoverflow.com/questions/50983943/function-timed-out-ensure-the-callback-is-executed-within-60000-milliseconds?noredirect=1&lq=1 would be helpful.

I'd also be interested to know whether it really does go to the URL as expected, as that might help us narrow down the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants