Dylan North

Dylan North

1569339155

Visually test VueJS apps using Cypress.io and Applitools

In my previous post, we explored how easy it is to troubleshoot and fix React bugs fast using React JS, Cypress.io, and Applitools. In this article, I’ll walk you through a complete, step-by-step guide of how to visually test a Vue JS app with Cypress.io and Applitools.

If you’re not already familiar, Applitools is an automated visual regression testing framework. It focuses on the visual aspects of your app — as opposed to functional testing — and plays a major role in exposing the visual differences between baseline snapshots and both current and future snapshots.


You may also like: Sharing data between components using event bus in Vue.js


So, let’s get going. First, make sure you’re familiar with these and have them installed on your machine:

Before we delve into writing code, let’s look at how Applitools and Cypress.io work together.

How Applitools Works With Cypress.io

Cypress.io offers extension points called plugins. Within a plugin, you can hook into and extend Cypress behavior. To read more on developing and building new Cypress plugins, check out this plugin documentation.

Applitools grabs this extension flexibility and builds the Applitools Eyes Cypress SDK as a Cypress.io plugin. Once installed, it adds a few commands to the main cy object. Specifically, it adds three main methods: cy.eyesOpen to start the test, cy.eyesCheckWindow to take screenshots (for each test step), and cy.eyesClose to close the test.

Nothing changes the way you write your tests with Cypress.io. You will have a few additional custom commands at your disposal to use with Applitools.

Let’s switch gears and start coding.

Step by Step Guide

For this demo, I’ve chosen to demonstrate the TodoMVC example, published as part of the examples projects on the Vue JS website.

Let’s follow the steps to run the TodoMVC app and add a few Cypress test cases.

Step 1: Install the Vue CLI 3 on your machine by issuing this command:

npm install -g @vue/cli
# OR
yarn global add @vue/cli

Once the Vue CLI is installed, you can start creating the Vue JS app.

Step 2: Create a VueJS app TodoApp by issuing this command:

vue create todoapp

The CLI asks a few questions to help you customize your app according to your requirements. For the scenario at hand, I will be selecting the following options:

First, select the manual option to allow you to customize the features of this app.

? Please pick a preset: (Use arrow keys)
  default (babel, eslint)
>  Manually select features

By selecting the E2E Testing option now, the Vue CLI will prepare the groundwork for you to write such tests.

? Please pick a preset: Manually select features
? Check the features needed for your project: 
(Press <space> to select, <a> to toggle all, <i> to invert selection)
(*) Babel   ( ) TypeScript   ( ) Progressive Web App (PWA) Support   ( ) Router   ( ) Vuex   ( ) CSS Pre-processors (*) Linter / Formatter   ( ) Unit Testing >(*) E2E Testing ? Check the features needed for your project: Babel, Linter, E2E ? Pick a linter / formatter config: (Use arrow keys)    ESLint with error prevention only    ESLint + Airbnb config    ESLint + Standard config >ESLint + Prettier ? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection) >(*) Lint on save    ( ) Lint and fix on commit

The second to last step allows you to select between two different E2E testing frameworks. For our example, select the Cypress (Chrome only) option. The CLI installs and configures the Cypress environment on your behalf.

? Pick a E2E testing solution: (Use arrow keys)
 >Cypress (Chrome only)    Nightwatch (Selenium-based) ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? (Use arrow keys) >In dedicated config files    In package.json

The CLI successfully generates the app, and you can run it by issuing this command:

 $ yarn serve

Step 3: Open the app in your favorite editor. (I personally use Visual Studio Code.) Locate the App.vue file and replace its content with the following:

View the code on Gist.

Step 4: Locate the main.js file and replace its content with the following:

View the code on Gist.

Nothing fancy here. I copied the code from the TodoMVC example and refactored it to fit into a Vue CLI app.

Now, let’s run the app to make sure everything is working. You should be able to see something like this:

Initial application output

_Initial application output_

Step 5: The Vue CLI places the Cypress.io related folders and files under the tests folder. The structure used is the one recommended by Cypress with the minor change of renaming integration folder to specs. Run the Cypress tests by issuing the following command:

yarn test:e2e

The Cypress test runner opens:

Cypress test runner

_Cypress test runner_

The Vue app and Cypress are both up and running. You may safely delete the specs/test.js file.

Time to start writing some E2E tests!

Step 6: Add a new specs/app_spec.js file with the following content:

View the code on Gist.

The single E2E test focuses on testing the functionality of adding a new Todo item. There are many tests that can be written, but for our sake, we will play around with a single E2E test to demonstrate the integration of Applitools with Cypress.io.

The spec file is self-explanatory. There’s just one thing to note here in relation to the selectors used inside cy.get() methods. The best practice is to avoid using IDs and CSS classes to select elements from the DOM. They will make your tests brittle because they’re subject to change. A better approach is to use data-* attributes or actual component names.

Now, switch back to the App.vue file, and go through all the data-* attributes I’ve added to facilitate writing this E2E test.

Step 7: Run the single E2E test by issuing the following command:

npm run test:e2e

Running our first E2E test

_Running our first E2E test_

Great! Our E2E test successfully passes and verifies that the app functions well and can add multiple Todo items without any issues.

E2E tests are sufficient in testing the overall Web app. However, wouldn’t it be beneficial and more effective to complement the E2E tests with visual ones? This adds the value of detecting any visual change or difference upon running E2E regression testing.

Let’s add the Applitools Cypress NPM package to the project.

Step 8: Add the Applitools Eyes Cypress SDK package to the project.

npm install @applitools/eyes.cypress --save-dev

Step 9: Locate the cypress.json file located at the root of the project folder.

Vue CLI has its own folder structure for Cypress folders and files. This special folder structure is different from that of Cypress.io. Applitools follows the same folder structure of Cypress.io. Therefore, we need to do some tweaking for Applitools to run safely inside the Vue CLI project.

Replace the content of the cypress.json file with the following:

{
 "pluginsFile": "tests/e2e/plugins/index.js",
 "baseUrl": "http://localhost:8081",
 "supportFile": "tests/e2e/support/index.js"
}

Step 10: Configure the Applitools Eyes Cypress SDK by issuing the following command:

npx eyes-setup

Now that Applitools Eyes Cypress SDK is well configured, we can start using it in our tests.

Let the visual testing begin!

Step 11: Revisit the specs/app_spec.ts file and replace its content with the following:

View the code on Gist.

The code is self-documented.

To integrate Applitools Eyes Cypress SDK into a spec file, you follow the Workflow below:

Start a new test

cy.eyesOpen({
    appName: '...',
    testName: '...',
    browser: { ... },
});

Take a snapshot (You may repeat this step wherever you want to take a snapshot)

cy.eyesCheckWindow('...');

End the test

cy.eyesClose();

Step 12: Run the spec file by issuing the following command:

npm run test:e2e

Running our second e2e test

_Running our second e2e test_

Notice the Applitools assertions at lines 1, 9, 17, 27, and 28. This type of logging is there to inform you about the steps Applitools is taking while Cypress runs your tests.

Step 13: Check the test run in Applitools Test Manager

Checking test in Applitools Test Manager

_Checking test in Applitools Test Manager_

Clicking on the test name (in this case Add todo items) yields the three snapshots that the Eyes SDK has taken during the running of the test.

The first snapshot is labeled first todo item added. The image shows the first todo item created.

The second snapshot is labeled second todo item added and shows the first and second todo items created.

The third snapshot is labeled third todo item added and displays the first, second, and third todo items created.

Since this is the first run of the test, Applitools will save these as the baseline.

We will simulate a visual difference by changing a CSS selector and let Applitools detect this. Now run the test again and see the results.

Step 14: Let’s assume that the CSS selectors were changed and caused a change in the font-weight of the text inside HTML labels. Add the following CSS selector to App.vue file as follows:

label {
 font-weight: 600;
}

Let’s run the test.

Step 15: Issue the command to run the E2E tests again. The test case fails, and Applitools detects a font-weight change for the labels used to display the todo item text.

Detecting font change for labels

_Detecting font change for labels_

Notice how the Applitools Test Manager recorded the second run of the test case and highlighted the visual difference in the three snapshots.

Step 16: Click on the first snapshot and compare to the baseline.

Comparing baselines

_Comparing baselines_

In case you can’t see both snapshots side by side, locate the View menu and select Show both.

Finishing our test

_Finishing our test_

In addition to the capacity to visually test your Vue JS apps, Applitools offers more functions and features to give you the upper hand in testing your web apps fast and locate the visual differences easily.

To play around with the source code of this article, feel free to grab a copy of the repo here: todomvc-vue.

Conclusion

You now have some insight on how Applitools speeds up your visual testing experience when you’re developing apps with Vue JS.

Happy Testing!

Originally published by Bilal H at dzone.com

#vue-js #javascript

What is GEEK

Buddha Community

 Visually test VueJS apps using Cypress.io and Applitools
Fredy  Larson

Fredy Larson

1595059664

How long does it take to develop/build an app?

With more of us using smartphones, the popularity of mobile applications has exploded. In the digital era, the number of people looking for products and services online is growing rapidly. Smartphone owners look for mobile applications that give them quick access to companies’ products and services. As a result, mobile apps provide customers with a lot of benefits in just one device.

Likewise, companies use mobile apps to increase customer loyalty and improve their services. Mobile Developers are in high demand as companies use apps not only to create brand awareness but also to gather information. For that reason, mobile apps are used as tools to collect valuable data from customers to help companies improve their offer.

There are many types of mobile applications, each with its own advantages. For example, native apps perform better, while web apps don’t need to be customized for the platform or operating system (OS). Likewise, hybrid apps provide users with comfortable user experience. However, you may be wondering how long it takes to develop an app.

To give you an idea of how long the app development process takes, here’s a short guide.

App Idea & Research

app-idea-research

_Average time spent: two to five weeks _

This is the initial stage and a crucial step in setting the project in the right direction. In this stage, you brainstorm ideas and select the best one. Apart from that, you’ll need to do some research to see if your idea is viable. Remember that coming up with an idea is easy; the hard part is to make it a reality.

All your ideas may seem viable, but you still have to run some tests to keep it as real as possible. For that reason, when Web Developers are building a web app, they analyze the available ideas to see which one is the best match for the targeted audience.

Targeting the right audience is crucial when you are developing an app. It saves time when shaping the app in the right direction as you have a clear set of objectives. Likewise, analyzing how the app affects the market is essential. During the research process, App Developers must gather information about potential competitors and threats. This helps the app owners develop strategies to tackle difficulties that come up after the launch.

The research process can take several weeks, but it determines how successful your app can be. For that reason, you must take your time to know all the weaknesses and strengths of the competitors, possible app strategies, and targeted audience.

The outcomes of this stage are app prototypes and the minimum feasible product.

#android app #frontend #ios app #minimum viable product (mvp) #mobile app development #web development #android app development #app development #app development for ios and android #app development process #ios and android app development #ios app development #stages in app development

iOS App Development Company in India

iOS app development company in India

India is considered the IT hub of the world because of n number of IT infrastructure development services offering companies. In this whole market iOS app development is the leading service offered by agencies across India

Want to develop the iOS app in India

WebClues Infotech with its head office in India has created a huge presence across the world over time and has served clients in all of the major countries around the world. WebClues Infotech with a highly skilled development team of 120+ members can help you deliver a better result at a reasonable cost.

Want to know more about our iOS app development services in India?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development company in india #ios app development company #ios app development #ios app #ios #hire ios app developer

iOS App Development Agency in the USA

iOS App Development Agency in the USA

Whenever a start-up in the USA launch an MVP version of the app they prefer to launch it only for iPhone user because the US has a large market of iPhone users in comparison to Android. The recent phenomenon of Clubhouse is the biggest example.

Want to develop an iOS app in the USA?

With 2 office locations across the USA and 6 worldwide, WebClues Infotech has the experience of serving a huge client base of 600+. After such a satisfied client base, WebClues Infotech is prepared to serve you with and iOS App Development Services in the USA.

Want to know more about our iOS App Development Services in the USA?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development agency in the usa #ios app development agency #ios app development #ios app #ios #hire ios app developer

Hire iOS App Developer

Are you looking to transform your idea into an iPhone application?

Hire iPhone programmer team from HourlyDeveloper.io to ensure the best results, utilizing all the latest trends in iOS app development, contributing to the overall success of your business. Hire iOS App Developer to feel that what the new technique of our iPhone Application developers can do for your successful business.

Contact with experts:- https://bit.ly/3fNpVqr

#hire ios app developer #ios app development company #ios app development services #ios app development #ios app developer #ios

iOS App Development Company in the United Kingdom

iOS App Development Company in the United Kingdom

Considering the two most popular operating systems Android and iOS, the latter one is comparatively less complex and needs less time to develop. So usually whenever a new app is launched it is launched on iOS platforms.

Want to Develop an iOS app in the United Kingdom?

WebClues Infotech with its presence across the world and an office in London as well has helped clients by completing 950+ projects in just 8 years since its launch. The project completion figure in such a short time shows the quality of work WebClues Infotech does and so clients trusted us with the iOS app development work.

Want to know more about iOS App Development Services in the United Kingdom?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development company in the united kingdom #ios app development company #ios app development #ios app #ios #hire ios app developer