Skip to content

[Question] executeJS action #214

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

Closed
mmularski opened this issue Aug 30, 2018 · 7 comments
Closed

[Question] executeJS action #214

mmularski opened this issue Aug 30, 2018 · 7 comments

Comments

@mmularski
Copy link

Hello
I need help with <executeJS> action.
Is it possible to get value from executed JS via <executeJS> action and pass it in different action?

I need something like example attached in documentation $myVar = $I->executeJS('return $("#myField").val()');
I know about <grabTextFrom> action, but before grabbing value I need to process it.

@ameysar
Copy link
Contributor

ameysar commented Aug 30, 2018

Hi @mmularski , could you try next code:

<amOnPage url="/" stepKey="navigateToStorefront"/>
<waitForPageLoad stepKey="waitHomePageLoad"/>
<executeJS function="return window.innerWidth" stepKey="execJs"/>
<assertNotEmpty stepKey="assert">
    <actualResult type="string">$execJs</actualResult>
</assertNotEmpty>

@KevinBKozan
Copy link
Contributor

@mmularski Yes it is possible to grab the value from an <executeJS> action.
The code block provided by @ameysar is correct, but just to add onto it, you can use the returned data like you would any grab* action:

<grabValueFrom stepKey="grabbedText" selector=".selector"/>
<comment userInput="Here is my grabbed text: {$grabbedText}" stepKey="showThatWeGrabbedIt"/>

@mmularski
Copy link
Author

mmularski commented Aug 31, 2018

@ameysar @KevinBKozan following code does not work for me:

<executeJS function="return (jQuery('.page-title').text().substring(1))" stepKey="invoiceNumber2"/> <fillField userInput="$invoiceNumber2" selector="{{StorefrontCustomerMyOrdersSection.invoiceNumberFilter}}" stepKey="fillInvoiceNumber"/>

It generates PHP like:
$I->executeJS("return (jQuery('.page-title').text().substring(1))"); $I->fillField("#invoice-number", "$invoiceNumber2");

but $invoiceNumber2 is not defined. I need something like:
$invoiceNumber2 = $I->executeJS("return (jQuery('.page-title').text().substring(1))"); $I->fillField("#invoice-number", "$invoiceNumber2");

@ameysar
Copy link
Contributor

ameysar commented Aug 31, 2018

@mmularski which version of magento2-functional-testing-framework do you use ? Provided example works on 2.2.0 and above. If you are using version lower than 2.2.0 code for executeJs will be generated without return value and in version >= 2.2.0 executeJs will have return value

@mmularski
Copy link
Author

mmularski commented Aug 31, 2018

@ameysar That might be this. I use MFTF 2.1.2, but when I'm trying to update to version 2.2.0 and generate a suite I got an error:

composer require "magento/magento2-functional-testing-framework":"2.1.2"
./composer.json has been updated                                                         
Loading composer repositories with package information
Updating dependencies (including require-dev)                                            
Package operations: 0 installs, 1 update, 0 removals
  - Downgrading magento/magento2-functional-testing-framework (2.2.0 => 2.1.2):  Checking out 10d547a984
Writing lock file
Generating autoload files
m2contribution@debian-8:~/www/dev.magento.pl/dev/tests/acceptance$ vendor/bin/robo generate:suite testsuite
Suite testsuite generated to _generated/testsuite.
m2contribution@debian-8:~/www/dev.magento.pl/dev/tests/acceptance$ composer require "magento/magento2-functional-testing-framework":"2.2.0"
./composer.json has been updated                                                         
Loading composer repositories with package information
Updating dependencies (including require-dev)                                            
Package operations: 0 installs, 1 update, 0 removals
  - Updating magento/magento2-functional-testing-framework (2.1.2 => 2.2.0):  Checking out 4dd196d745
Writing lock file
Generating autoload files
m2contribution@debian-8:~/www/dev.magento.pl/dev/tests/acceptance$ vendor/bin/robo generate:suite testsuite
PHP Notice:  Use of undefined constant MAGENTO_BP - assumed 'MAGENTO_BP' in /home/www/m2contribution/www/dev.magento.pl/dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php on line 225
Suite testsuite generated to _generated/testsuite.
ERROR: Use of undefined constant MAGENTO_BP - assumed 'MAGENTO_BP' 
in /home/www/m2contribution/www/dev.magento.pl/dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php:225

@ameysar
Copy link
Contributor

ameysar commented Aug 31, 2018

@mmularski please check documentation. Before generating tests you should build project by next commant
vendor/bin/robo build:project

@mmularski
Copy link
Author

mmularski commented Aug 31, 2018

@ameysar vendor/bin/robo build:project does not fix the problem.
removing vendor/, composer.lock and composer install command too. Everything I've done with documetation.

ERROR: Use of undefined constant MAGENTO_BP - assumed 'MAGENTO_BP' 
in /home/www/m2contribution/www/dev.magento.pl/dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php:225

Edit:
After adding MAGENTO_BP to .env file, suite has generated successfully, and variable has been created for <executeJs> action, thank you :)

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

No branches or pull requests

3 participants