In Magento, there are various “repetitive” tasks to check such as testing with different input values. These repetitive actions take a lot of time. To do this we can use JSON data in CasperJs script.
Use of JSON data in CasperJs Script.
Here I have created a login.json file which contains 3 key i.e. link, email & password with their respective values, which is used for the login process.
login.json
/** * Webkul Software. * * @category Webkul * @package Webkul_CasperJS * @author Webkul * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ { "link": "http://example.com/mage3/customer/account/login/", "email": "[email protected]", "password": "xyz123" }
Passed values in CasperJs script: Here I have created json object and assigned login.json to json object through require method. Then created email and password object and assigned the value of email key and password key respectively and called the link key (Magento frontend login page link) for starting the login process.
signin.js
/** * Webkul Software. * * @category Webkul * @package Webkul_CasperJS * @author Webkul * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ var casper = require('casper').create({ verbose: true, }); var json = require("login.json"); var email = json['email']; var password = json['password']; //Home page link casper.start(json['link']); //Login Form Fillup casper.waitForSelector('#login-form', function () { this.fill('form#login-form', { 'login[username]': email, 'login[password]': password }, false); }); //Click Sign In Button casper.then(function () { this.click('#send2'); }); casper.wait(3000, function () { this.echo("Successfully Logged In", "COMMENT"); }); casper.run();
For complete Magento2 frontend login process check our blog How To SignIn Magento2 Frontend Using CasperJS
Be the first to comment.