Dealing with new tabs in Cypress

Cypress is an amazing tool with some of the best features for developers and testers alike. But by its own admission. Cypress can never handle controlling multiple tabs, or one browser at a time.

This may put you off investing the time into learning and using this unique and modern tool. Selenium can drive multiple browsers and tabs without much effort. Why not just pick that over Cypress?

And although it’s a valid point, it’s important to note that these disadvantages are due to the unique architecture of Cypress which, in the developer’s own words:

In a sense they prevent you from writing bad, slow, or flaky tests.

Are you sure you want to do that?

Let’s look at this from a practical point of view. Is there ever going to be a test you will need to automate that calls for the independence of two browser windows or tabs?

My guess is most likely not.

Of course, there will probably be some scenarios where this functionality is desirable. But if you want your automation suite to be fast, agile, and not a drain on memory and processor usage. I am going to make the case that sticking to one tab per test is the best setup that you should strive for.

Not only is this good practise to truly ensure that you are isolating your test cases. But also helps protect you from any browser quirks or behaviour that could add unwanted flakiness to your test code.

So instead of a test dependent on your ability to control two independent browser windows or tabs. I would say that you should instead take the approach of two separate tests.

Given the case of a new browser tab opening when a button is pushed, for example. I would advocate that one test be dedicated to testing everything before the new tab is launched, including the new tab being called. And then a separate test dedicated to testing everything post the new tab being called.

So what is the solution that Cypress provides?

One of the most versatile features that Cypress comes with is the ability to stub a network request. Providing you with a way to not only tell when a call has been made to a function. But to also take control of its behaviour and really provide testers with the ability to take control of how the application performs instead of the other way around.

When you include a stub inside your code. The object that is returned is an actual value object that can be asserted on instead of a promise like object.

So in the example’s case defined above. We first need to stub the browser opening action so that Cypress can monitor when the action is called and assert on the stubbed object instead of executing the default action.

To do so include the following code:

onBeforeLoad(win) {
            cy.stub(win, “open”).as(“windowOpen”);
}

To provide a little more context to this code. We are saying to execute the code within the function before the browser window loads. We are also passing in the window object so we can apply our stub.

Next, we are saying that when the open call is made to the window object. Alias it with the windowOpen name.

Finally, we have to code in an assertion that ensures the alias is called and crucial for our test. This will not open a new browser window, and our test code will continue without interruption.

cy.get(“@windowOpen”).should(“be.called”);

Putting this all together. Your test code should look something like this:

    
    cy.visit(“www.samplepage.com”, {
        onBeforeLoad(win) {
            cy.stub(win, “open”).as(“windowOpen”);
        },
    });

    cy.get(“button”).contains(“New Window”).click();

    cy.get(“@windowOpen”).should(“be.called”);

Wrapping it all up

This is just a simple example of how you can use the versatility of Cypress to get around the problem of dealing with multiple browser windows.

Yes, Selenium can do so, and it does it pretty well. But as I talked about earlier. There is no such thing as a free lunch and while it may seem that you are gaining extra functionality. You might make unwanted trade-offs and unknowingly introducing unreliability to your test automation.

Cypress isn’t a perfect solution. No tool can claim to be perfect. But in the hands of someone who has knowledge of its strengths and limitations. The tool can be just as useful and powerful as any other on the market today.

I hope this blog post was useful to you.

Reach out to me on LinkedIn or Twitter if you have questions. Or contact me using my contact form.

PS: I also send out a weekly newsletter which contains links to articles I’m reading, the books I’m enjoying. And other interesting content. Sign-up here if you’re interested. It’s free!

My top four Chrome extensions for software testers

A few weeks ago, I shared my favourite tools to aid me with my software testing activities. I created that post to not only document the software that I find helpful. But to also shine a light on packages that might be unknown to some people and to promote discussion of alternative solutions.

As I mentioned in that post. A tool’s purpose is to only help you be productive in a task. It’s not a magic bullet and if you don’t know how to do something. The tool won’t be able to do it for you.

One key software product that I missed out from that list is probably the most frequently used item in many testers toolboxes, which is the web browser.

Although I am a Firefox user outside of testing. The browser share is significantly in Google Chrome’s favour and even though it is still a major browser. Chrome is still my testing tool of choice for 90% of my daily tasks.

In this post, I will go through some of my favourite extensions which when enabled. Turn it into my ultimate testing web browser ?

Read More

How to build your reputation as a software tester

Being the person who is not concerned about other people’s opinions is often touted as being the secret to a happy life. Why spend your energy being concerned with what your neighbour might or might not be thinking about your latest actions. When you can instead use that energy to focus on yourself. Cultivating a mindset and an existence that makes you happy.

Unfortunately, when it comes to your career and those who will hire you or potentially working with you. What they think of you will often be the biggest factor that decides whether they want to do business with you, or someone else.

Your reputation is something that follows you throughout your career. Added to by the people you’ve worked with, the impressions you gave others. And the actions you have taken. While it is not an exclusive career orientated currency. A good reputation is also something to be valued throughout your life. And knowing how to keep it, maintain it and ensure it grows over time is a skill that we all need to have a bit of knowledge on.

Not only because it is much easier to find out these days what other people think of someone or the past achievements of someone via a quick Google search or a peak on various social media platforms. But also because reputations often proceed us, they can be passed around via word of mouth and reach more people than ever before.

The upside of this however is that with a more globally connected world. We can use this to our advantage and highlight ourselves to ensure we stand out from the crowd, rise to the top of the pile, and be sought after by hiring managers.

Read More

How to turn an obstacle into your advantage

In the year 170 AD which saw intense fighting between the empire of Rome led by emperor Marcus Aurelius, and various Germanic and nomadic tribes (known as the Marcomannic wars). Marcus Aurelius sat down during some much-needed time to himself and began transcribing his thoughts.

The exact place that he wrote or even the intention for the scripture at the time are of little importance to us now. Some scholars claim that these would be works that his sons could reference long after his passing. Others claim they were merely an exercise in self-reflection. With the intention to simply remind him of the philosophical beliefs that he held onto and needed to be reminded of when sailing through turbulent waters.

Today we know these as The Meditations. Our best resource for understanding the ancient philosophy known as Stoicism.

Held within these pages of personal writings and private notes is the following quote:

“The impediment to action advances action. What stands in the way becomes the way.”

Read More

Is the Cypress Dashboard right for you?

Cypress is an open-source end-to-end testing framework written in JavaScript and released for free under the MIT license.

In no way are you required to pay to use the tool, write or run your tests (locally or remotely), or to make use of your own custom reporting solution. If you want to use additional tools like mocha-awesome, go right ahead.

And as a test automation tool, it is one of the most popular and widely used for testing the latest generation of web applications released today. Not only because it uses the language of the web (JavaScript) and is crazy fast. But also because of its easy-to-use API, amazing built-in features that allow you to travel back in time to see failures in an application at the point of their discovery. But it also saves time by integrating with multiple CI environments. Enabling developers to ship features faster and get quick feedback on overall software quality. There’s nothing worse than shipping additional features to discover that it had a negative impact on another part of your codebase.

I’ve been using Cypress exclusively for a while now. But I’ve been missing a way to analyse my test execution statistics in a centralised location. Having to rely on several custom tools, which although work. Still don’t provide all the statistics and insights that I would like.

I’d like to preface this by saying that although Cypress itself is free. The Cypress Dashboard is a paid service that is not required for Cypress to operate. However, it is an interesting product in its own right that provides many features ‘out of the box’ that some people might not have time to configure themselves.

So let’s go into these and conclude on whether it is something that fits your needs.

Read More

Five habits to adopt in order to be a better software tester

No matter how many cloud services I sign up to, or organisational systems I utilise to structure my files on my local laptop. I always seem to run low on storage.

One obvious remedy to this common problem is simple to upgrade the amount of space available to me by throwing in another drive into my laptop.

But is this really a solution?

More resources may seem like a likely fix to most problems. But unless I fix how I use the storage I already have in my laptop (delete old files, uninstall programs I no longer use. Not download every meme that I come across). Then I’m not really solving anything. I’m merely patching things and delaying the problem so it now becomes something that future me needs to deal with.

Another example of this is probably familiar to us all. When our alarm clock goes off in the morning, the temptation to hit the snooze button can almost seem like a tempting solution to the constant buzzing and feeling of only wanting to get five more moments of shut-eye.

The alarm clock sounding might be your problem right now. But as soon as you hit that snooze button, it becomes a problem for future you to deal with when you wake up late for work.

To solve this, you could put your alarm clock across the room. Forcing you to get out of bed to turn the buzzing off. But then you’d be relying on your discipline to not just go back to bed and cause another problem for your future self.

Or, you could instead work on the habits to increase your chances of waking up with your alarm clock and not causing problems for yourself down the line.

Prevention is always better than cure.

This is the cornerstone philosophy behind building positive habits. If you want to be better at what you do and not leave things to discipline, or chance. Take the time to invest in yourself and build up your foundation and give yourself a better likelihood of overall future success.

But how can we take this idea and apply it to our career?

Well, at some point you’ve probably come across the saying:


“We are the sum total of our experiences. Those experiences – be they positive or negative – make us the person we are, at any given point in our lives.”

BJ Nebit

So given that idea. It’s probably safe to say the person we bring to work is also the sum of all the activities we do in our daily lives.

So to prevent ourselves from succumbing to the failures that inevitability, we will experience within our working lives. It’s critical to build up several experiences that we can not only rely on to provide us with the insight and knowledge that will become invaluable to us. But also enable us to discover more about the key skills that feed into our area of expertise and allow us to become a more rounded professional.

And the best way of doing that. Is to adopt new habits, hobbies and interests to provide you with a unique set of skills and abilities. Thus building yourself strong springboard to catapult yourself into future career success.

Here are five habits that I personally would recommend to any new, or veteran software tester. Not only will these provide you with a wide knowledge base. But they will also provide you with a depth of varied subject areas that you can draw on to solve problems, tackle issues. And break down any barriers that will stand in your way.

Be curious about all aspects of software development

Knowing the software development methodologies like waterfall, agile and DevOps will benefit your ongoing knowledge. But I find it more interesting to go deeper and really understand the details about the software development process. And I’m not just talking about the languages that used in development, although that will help. I’m more interested in the application frameworks used, the services that are being utilised and any API’s that are being consumed.

Getting comfortable wanting to know the details about the technology stack of an application will not only assist you in designing and developing your tests. But it will also help you understand the limitations of the application. And how you can integrate your testing so that you are more closely aligned with the underlying technology and ensure a more robust testing solution.

Read non-fiction books

If you want to become better at anything in your life. You can guarantee that someone has not only done want you want to do already. But they have also probably wrote about it too.

Next to software development, software testing, and watching cat videos on YouTube. Reading is my personal biggest hobby, and I put reading down to being behind the person I am today.

Whether it’s a book about military leaders, economics, mental models, or finance and business. Acquiring the positive habit to read even a few minutes a day will do wonders for not only your thinking. But also for your career and will pay dividends for years to come.

Don’t forget the soft skills

Another key habit to not neglect is the set of skills often referred to as ‘soft-skills’.

Essentially, these are defined as the combination of people skills that encompass communication, social skills. But also our attitudes and character traits.

These skills don’t come easy to most people and it is something that a lot of us need to gain through practice if we are going to not only get along with the people we work with. But also succeed in our role and enable others to feel comfortable in collaborating and working with us.

Communication is a critical skill that all software testers need to be good at. And it is often mentioned by hiring managers as the one skill which candidates need to have.

I’ve written a blog post on tips to be a better communicator here.

Question others, but also question yourself

And finally, be comfortable asking questions.

Testing is a discipline that relies on the influx of information to be successful. And even though some people may become annoyed with your ever-growing list of questions. The risk of not asking questions is in my mind a greater problem than not asking.

And as part of the questioning process. You should first start with yourself.

Question your own beliefs, your own assumptions, and your own understanding.

This not only highlights areas of misunderstanding in your own mind. But if also a great exercise to undertake to help you plan brilliant questions to ask other people.

I hope this blog post was useful to you.

Reach out to me on LinkedIn or Twitter if you have any questions. Or contact me using my contact form.

PS: I also send out a weekly newsletter which contains links to articles I’m reading, the books I’m enjoying. And other interesting content. Sign-up here if you’re interested. It’s free!

Are there any limitations to test automation?

Isn’t it great when one solution works for any problem that you might have?

When I was a kid. I was always curious why older people were always trying to boss me around, telling me where to go and what to do. Then I discovered the response ‘Why?’. And while it helped to satisfy my curiosity for a while. I soon discovered that it had the side effect of being quite (understandably) annoying and therefore, it’s usefulness waned over time.

Or how ten years ago if a company wanted to make the tech product better. The go-to solution would be ‘Add Bluetooth to it!”.

Kinda reminds me of that scene from Big Bang Theory.

Read More

How to make your GUI test automation less flaky and brittle

Change is inevitable for the GUI of a web application, or any part of it.

For a visual example of this, look at the Google homepage from the mid-2000s. And you will see a site that has the same features of today (minus references to several Google products), but if a test automation solution was written then that depended on the layout and overall design of the page. It probably wouldn’t work with the design of today.

I know this is probably a bit of an extreme view of things. The design of a web application from over a decade ago won’t be the same today. But thinking in extremes when faced with a problem is a useful tactic to adopt to unlock the solution.

Offtopic, but if you are interested. I’d recommend watching this TedX Talk on the subject.

Using this thinking, we can then work backwards and make informed decisions about the design choices we make, the selectors we target. And the features that we will create automated solutions for.

If you want to learn more about the kinds of tests that should be automated. Check out this blog post. But we don’t want to automate something if it’s a feature that is not going to be used going forwards, or it makes little sense to automate because of time constraints.

Read More

How to run your Cypress tests in multiple environments

Cypress as a testing tool is flexible in the sense that we can use it for mocking HTTP response, re-create complex user interactions as well as monitoring, and responding to network requests.

Plus, it’s written in JavaScript!

This may or may not be a plus for some. But considering it’s the de facto language of the web at the moment. It means that one language can be used for the web application stack. And powering your testing solution and enabling seamless collaboration with developers, testers, and even technology savvy stakeholders.

YAY, JavaScript

Just as a side note, these are not reasons alone to choose Cypress over another test automation tool. I have written before on the topic and advocate using the right tool to get your job done. But seeing as this is a blog post on Cypress, I’m going to assume you have already made that decision and want to find out more on how to use a single code base for testing across your multiple environments. So let’s keep going.

Read More

Why you need to have a dashboard

Software testers are many things to many people. We are analytical, technical and above all, curious about the software that we are testing. And while those descriptions are true, the traits we hold alone can not summarise the value that we provide to software development teams..

There is a distinction between what something is and what something does.

For example, my car’s engine is noisy and needs maintenance to function. But I can’t say that my car is defined by those characteristics.

If I told someone with no knowledge of cars that information. They would have little idea of what I am talking about except discovering that car engines are noisy and need to be maintained. Whereas if I told them my car’s job is to enable me to drive anywhere I need to go and to allow me to get places much quicker than walking. They would have a better understanding of what a car is.

This idea stems from Richard Feynman who once said, “Names don’t constitute knowledge”.

I would take that one step further and say that descriptions alone don’t equal the purpose of something.

Read More