Menu Close
    Hire us Request quote Reading list Switch to dark mode

    How To SignIn Magento2 Frontend Using CasperJS

    Manual Testing is a time consuming and tough task to do. In manual testing, it happens to do same tests many times like create a new account, sign in, order placement etc for magento2 store, which is boring. There are some good tools available which make it easier. CasperJS is one of them. CasperJS comes with a basic testing suite that allows you to run full featured tests without the overhead of a full browser. It uses selector and events to do tests.

    For the installation and basic CasperJS knowledge, you can check here. Now we’ll proceed with the testing process. Here we’ll learn how we can sign in using CasperJS for magento2 store. This script will also show you proper error messages for wrong inputs

    The script procedure is as follows-
    Open home page of your Magento2 store, click on “SignIn” link, Fill Login Form, Click on SignIn button, wait to be redirected to “My Account Dashboard” page and then get the title of My account page.

    Here we have used some CasperJS methods like-

    start(): For Opening Magento2 Store Homepage

    casper.cli.get(0): For getting input from the terminal. Here 0 is an index of input.

    waitForSelector(): Waits until an element matching the provided.

    click(): method is used to click a link and buttons.

    fill(): method is used to fill the forms.

    exists(): Checks if any element matches with the provided selector

    wait(): wait for given amount of time

    bypass(): To Skip a given number of defined navigation steps

    fetchText(): Retrieves text of given selector

    getTitle(): Retrieves page title


    Now you have to run a command on your terminal-

    casperjs your_file_name.js http://your_magento_homepage email_id password

    Here, you can see the result on your terminal –

    For blank input –

    For invalid email or password –

    After running the test script you will get the Dashboard page title if successfully logged in or error message for wrong inputs.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close