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

No chain? #84

Open
thezimmee opened this issue Nov 9, 2017 · 3 comments
Open

No chain? #84

thezimmee opened this issue Nov 9, 2017 · 3 comments

Comments

@thezimmee
Copy link

Hello. Thank you for chromy, I can't wait to get it running. I am trying to write a thin wrapper around it to pass some config to tell it to run certain test and/or screenshots. So I'm trying to conditionally call different chromy methods, but I don't see any examples that show using chromy not in a chain. I also can't find any documentation for what the chain() method actually does. To be clear, I would like to do something like this:

let chromy = new Chromy({port: port++});
let browser = chromy.chain()
  .emulate(deviceName)
  .goto(test.url);

if (runStartCallback) {
  browser.evaluate(() => {
    return onStartCallback(browser);
  });
}

if (multipleSelectorsConditionIsTrue) {
  browser.screenshotMultipleSelectors(selectors, callback, options);
}

if (documentScreenshotConditionIsTrue) {
  browser.screenshotDocument(options);
}

if (runEndCallback) {
  browser.evaluate(() => {
    return onEndCallback(browser);
  });
}

browser.end()
  .then(() => {
    chromy.close();
    console.log('DONE!');
  }).catch((error) => {
    chromy.close();
    console.log('ERROR', error);
  });

The reason I need to do something like this is to be able to pass config to conditionally do certain things and call certain callbacks methods which allow the user config to interact with chromy. I'm missing something because I'm getting various errors, a common one being:

Error: 'then' is not defined on a target object.

How can I accomplish what I am trying to do? I appreciate your help.

@dotneet
Copy link
Contributor

dotneet commented Nov 10, 2017

Hi @holmescn, thank you for using chromy.

Basically your code seems to have a problem.
But I'm curious of the part of the code.
where are onStartCallback() and onEndCallback() defined?
The function passed to .evaluate() is executed with browser context.
So can't call a function or variable in nodejs context.

The chain is implemented by async-chain-proxy package.
You can check the behavior of chain by accessing this package directly.

@alii
Copy link

alii commented Feb 21, 2019

@dotneet would it be possible to pass data to evaluate like this:

await chromy.evaluate((data) => {window.blah(data)});

Edit: or is there another way?

@dotneet
Copy link
Contributor

dotneet commented Feb 22, 2019

Hi @aabbccsmith,

evaluate can receive arguments.
https://github.com/OnetapInc/chromy/blob/master/test/evaluate.js#L52

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

3 participants