Java Design Patterns: Implementing a singleton for Selenium WebDriver

What is a Singleton? A singleton is a class which should only be initialized once, provide a way to allow multiple instances of that class to be used, and finally to be the central point of access for that class.

Typical use cases of a singleton are classes accessing to system resources. In my scenario I want for example to create a singleton for Selendroid, since I really want to create just one instance of Selendroid to run all my tests.

Continue reading Java Design Patterns: Implementing a singleton for Selenium WebDriver

Adding Maven to a project in IntelliJ

Previously I used the jar libraries for the Selenium/Selendroid project to work fine, however the method is not really ideal. Project dependencies should be imported automatically with a dependency sistem of some sort. Here I am going to add Maven to the project and manage the dependenices through it. Here I am going to add selenium-java and selendroid-standalone, but this is of course valid for any other library.
Continue reading Adding Maven to a project in IntelliJ

Accessing an iFrame through Selenium WebDriver

Selenium is great for testing web applications in general, however one of the least used things in this space are iFrames. You might be interested into them because you want to automate logging in, or because you have sandboxed elements into your application.

Fortunately, in Selenium is quite easy to achieve this result: all we need to do is to switch context, which can be done in three separated calls.

  1. Find the iFrame element
  2. Switch the driver to the iFrame
  3. Play with the contents of the iFrame!

Continue reading Accessing an iFrame through Selenium WebDriver

A simple test with Seledroid

So now that we know that Selenium is working as we expect (I am a newbie here), we can try adding Seledroid. If you haven’t used Selendroid before, I strongly recommend you to follow the initial setup guide, available here. Basically you will need to have JAVA_HOME and ANDROID_HOME variables correctly set up in your system.
Continue reading A simple test with Seledroid

Getting ready to write our first Selenium Test in IntelliJ

Before getting into using Seledroid, it is probably a good idea to see if my old understandings of Selenium still apply. I haven’t used it in ages, so as a first step I will configure an IntelliJ project using Selenium.
Continue reading Getting ready to write our first Selenium Test in IntelliJ

Mobile Testing in Android with selendroid

It is always a problem automating testing in the mobile world, because the technologies used in the desktop world are not capable of the same level of testing, therefore we are looking for technologies that will allow us to at least do some level of mobile testing.

Selendroid

seledroid-logoThe first tool we are going to try is Selendroid, which seems to be the standard tool when it comes to Android mobile testing.

Selendroid uses the JSON Wire protocol, ready for Selenium 3. It makes possible to test native, hybrid applications and the mobile web. In our scenario we’re interested to the last two. Also Selendroid supports simulated devices as well as real ones.

Event.isTrusted property from UI Events shipped in Chrome 46

Working on a large JavaScript project is not easy. We need fine tuning in everything we do, and sometimes we need to distinguish between a user-generated event and an event generated by a script.
Why is this important? Because the ability to distinguish between a user initialized action and a scripted one can make the difference to optimize the UI.

Continue reading Event.isTrusted property from UI Events shipped in Chrome 46

Beginners Guide to Landscape Photography

Tips, settings, compositions   Last Light Besides passion & patient, to photograph great landscapes photos, it takes a fair amount of preparation and skill in basic photography technique. This article focuses on some important, but not all, aspects of landscape photography that photographers need to master when photographing landscape. Don’t leave home without them. We are referring to gear other than the obvious two, your camera and lenses.

Continue reading Beginners Guide to Landscape Photography

The most efficient way to listen for a resize

In Android when the keyboard shows up, the size of the window will change triggering a resize event on the window.
When the resize event would get fired on a mobile device?

  • When the keyboard shows up
  • When rotating the device
  • When the browser window shrinks because the user uses a multiwindow view

Now we want to listen to this event just once and then act, avoiding to do too much because it would impact on the frame-rate of our application. I could argue here that the keyboard component will only fire one window resize event however this cannot be guaranteed; In the Android market there are literally thousands of different keyboards and might be that one of them is going to fire the resize event more than once, causing difficult to debug behaviors once they get reported by a user.

Also another scenario would be that two resize events are quite close for example when the user does some operations it will hide and show the keyboard quite quickly, firing the event at least twice in few milliseconds.

We need to use setTimeout and clearTimeout in a clever way:


function actionOnResize (e) {
  // do stuff
  console.log('do something');
};
var action;
window.addEventListener('resize', function (e) {
  clearTimeout(action);
  action = setTimeout(function () {
    actionOnResize(e);
  }, 50);
}, false);

A perfect delay

Depending on the application specifications you need to find a good delay for this to fire accordingly. In my scenario a delay of 50ms has been what I needed for.