Thursday, 29 June 2017

Can we display "Hello World" without using a semicolon in C ?

Well the answer is YES!. But to understand this we need to cover some basics of ‘function’.
Don’t worry I am not going to explain the basics of function. As I assume you know it. I am sure you are also familiar with the term “return” which is frequently used inside the function. We also know that every function must return a value. This statement is the key to solve this puzzle. Yes you heard it right. Having said that, Lets understand what kind of values are returned by most frequently used functions? For example, printf()

Whenever we use printf() function, what we expect is the Output display on the screen. We hardly care about what kind of value does it returns. Let’s check it out.

main()
{
int valueReturned = 0;
valueReturned = printf(“Welcome to Programming!”);
printf(“\n %d”, valueReturned);

}

What do you think will be the output? “Welcome to Programming!” is going to be displayed on the screen for sure. But I am interested in the value of the variable named, valueReturned. If you run this program in any C compiler it would show the output as given below
                      Welcome to Programming!
                      23
Well, This 23 is nothing but the length of the string enclosed within the double quotes which we usually see on the screen. Which means, something like printf(“%d”, printf(“Hello World”)); will give an output like “Hello World11”. Further, to enhance your learning, you should check the output for the statements like
printf(“%d”, printf(“\n Hello World”)); printf(“%d”, printf(“\t Hello World”)); etc. to understand whether '\n' counts as 0, 1 or 2 characters?

Now if you have understood this, we are half done. Next thing which we need to understand to solve this puzzle is the conditional statement “if()”. Relax! I am not going to start talking about the basic functionality of the “if” keyword here. I assume you guys know this. What I wanted to discuss here is, in the if() section, Some people think that, if you pass 1 and 0 it is evaluated as True and false respectively. In fact, Any Non Zero value passed inside any conditional statement evaluates to true in C language. For example, you must have seen the example of infinite loop in most of the text books is written as “while(1){}”.

We are done with theory part of the puzzle, now it’s time to write the code.

main()
{
    if(printf(“Hello World”))
       {
       }
}

If you run this program, It will not throw any compilation error and will display the text
Hello World” on your screen.




Tuesday, 27 June 2017

What will be the range of an integer data type of size 3 Bytes or 5 Bytes??

In C programming or any other programming laanguages, there is a term called range of the data type say “int”. If I talk about the C programming specifically, the size of an int data type is 2 bytes or 4 bytes depending upon the operating system used. Let’s assume the size of an int data type is 2 bytes for this moment. What should be the range of int now?

Well, if we talk about signed int, then its between -32768 to 32767. It’s something that we read in a textbook or any other source. How is it calculated? Let’s find it.

As we know, 1 Byte = 8 bits. Which means 2 Bytes = 16 bits. So the Maximum number this data type can store is 216. Which equals to 65535. Let’s understand this. We said it’s 16 bits, means we can have two values i.e either 0 or 1 for each bit.

0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1
0 , 1

That is why the range of an unsigned int lies between 0 – 65535. If we talk about the signed int range, then it’s -215 to 215 – 1. As we reserve the left most bit for the sign. So we are left with only 15 bits for storing the values.

So whenever we need to calculate the range of any integer data type, we need to get the size of that data type so that we can calculate the total number of bits. Once the total number of bits is available we can calculate the range(unsigned) by simply 0 - 2(total number of bits). Similarly, the signed range of that data type would be: - 2(total number of bits – 1) to 2(total number of bits – 1) -1.

Why that -1 ?? Well it’s because 0 is treated as positive number. For example, if we have to divide 10 numbers in to equal parts the division would be like....

                     -5   -4   -3   -2   -1   0   1   2   3   4

So let’s calculate the range of a hypothetical integer data type which takes 3 Bytes in memory. 3 Bytes means 3 * 8 = 24 bits.

So the unsigned range will be : 0 – 224
And, signed range will be : - 223 – 223 – 1


Hope you can calculate the range of integer data type of any size. 

Sunday, 18 June 2017

How compilers treat the operators like "++" and "--"


The operators like pre-increament(or decreament) and post increament(or decreament) is very commonly used operators for the programmers. It is widely used in the loop. I know, it’s pretty simple to understand. Well, It’s not restricted to be used for the loop only. It can be used for a simple instructions like
++i * ++i * --i * i++ ....
It’s tricky to get the correct value of this operation. And, It totally depends upon the compiler you are using. I always used to get stuck in thses kind of operations. But today I would like to share my understanings with you guys.
Okay!, Lets start with the most popular language, i.e., C Language and see how C compiler treats this ++ and – opeartor when used for the calculation.
Let me write a small piece of code
main()
{
int x = 3, y, z;
y = ++x * ++x * ++x;
printf(“The Value of y = %d”, y);
x = 3;
z = x++ * x++ * x++;
printf(“\n The Value of z = %d”, z);
}
Any Guesses? Well, The value of ‘z’ is not hard to get but the value of ‘y’. The output of the above written code is :
The Value of y = 216
The Value of z = 27
Surprised with the value of y? As I mentioned earlier, it totally depends upon the compilers, but in most of the C compilers you will get the same value.
Okay, let me tell you the logic now. Whenever the “++” or “--” operators are used for the operations like in the above code. It’s value are pre-calculated. Further, the calculated value used for the rest of the operations.
e.g.,
x = 3;
y = ++x * ++x * ++x;
As we can see that, the “++” operator has been used three times here, so the value of x would be
x = x+3(only for pre-increament operator)
i.e, x = 6;
now the y = 6 * 6 * 6, i.e 216.

Well, The compilers like Java or JavaScript will give a different output, In Java or JavaScript, the output would be simply 4 * 5 * 6 = 120. It’s perhaps the C language only who treats these operators in this way. Anyways, what if there is a mixture of pre-increament and pre-decreament operator? Something Like,  
int i = 2, j;

j = --i * ++i * ++i * ++i * ++i * --i;

It’s pretty simple, “--” has been used twice while “++” used for four times. So basically it’s two times “++”. Yes, you can cancel out each “--” with a “++” and  vice versa.

now the final value of i is

i = i+2, i.e., 4

j = 4 * 4 * 4 * 4 * 4 * 4;

j = 4096.

In Short, 
Remember, since "++" or "--" is having the highest priority among all the operators so we need to pay attention towards this operator. Calculate the final value of the variable, by counting the number of "++" and "--" associated with the variable and cancelling out each "++" with "--" and vice versa. Preceed with this final value to perform the rest of the calculation. 
 




Sunday, 11 June 2017

JavaScript : Difference between Null and Undefined

The undefined value is a primitive value used when a variable has not been assigned a value. The null value is a primitive value that represents the null, empty, or non-existent reference. When you declare a variable through var and do not give it a value, it will have the value undefined. By itself, if you try to WScript.Echo() or alert() this value, you won't see anything. However, if you append a blank string to it then suddenly it'll appear:
var s;
WScript.Echo(s);
WScript.Echo("" + s);
You can declare a variable, set it to null, and the behavior is identical except that you'll see "null" printed out versus "undefined". This is a small difference indeed.
You can even compare a variable that is undefined to null or vice versa, and the condition will be true:
undefined == null
null == undefined
They are, however, considered to be two different types. While undefined is a type all to itself, null is considered to be a special object value. You can see this by using typeof() which returns a string representing the general type of a variable:
var a;
WScript.Echo(typeof(a));
var b = null;
WScript.Echo(typeof(b)); 
Running the above script will result in the following output:
undefined
object 
Regardless of their being different types, they will still act the same if you try to access a member of either one, e.g. that is to say they will throw an exception. With WSH you will see the dreaded "'varname' is null or not an object" and that's if you're lucky (but that's a topic for another article).
You can explicitely set a variable to be undefined, but I highly advise against it. I recommend only setting variables to null and leave undefined the value for things you forgot to set. At the same time, I really encourage you to always set every variable. JavaScript has a scope chain different than that of C-style languages, easily confusing even veteran programmers, and setting variables to null is the best way to prevent bugs based on it.
Another instance where you will see undefined pop up is when using the delete operator. Those of us from a C-world might incorrectly interpret this as destroying an object, but it is not so. What this operation does is remove a subscript from an Array or a member from an Object. For Arrays it does not effect the length, but rather that subscript is now considered undefined.
var a = [ 'a', 'b', 'c' ];
delete a[1];
for (var i = 0; i < a.length; i++)
WScript.Echo((i+".) "+a[i]); 
The result of the above script is:
0.) a
1.) undefined
2.) c 
In short, JavaScript will never set anything to null, that's usually what we do. While we can set variables to undefined, we prefer null because it's not something that is ever done for us. When you're debugging this means that anything set to null is of your own doing and not JavaScript. Beyond that, these two special values are nearly equivalent.

Saturday, 3 June 2017

5 Mistakes to Avoid When Building Your Mobile App



Mobile apps are extremely popular at the moment, and they’re paving the way for all kinds of new and exciting business ideas. The problem, especially for many of the smaller-sized bussiness, an individual or the freelancers is to figure out the right approach.

 

1. Building for Multiple Platforms at Once

Let’s face it, with over one million apps on both the Google Play and Apple App Store, you are playing in a very competitive space.
Avoid doubling your engineering costs and focus on building on one platform first. This also helps get your minimum viable product (MVP) out in the app store as soon as possible.
In addition, if you do launch on both platforms at once and need to make any changes to design and/or functionality, then you will need to do it on both places which adds more development time and cost.
It’s better to finalize an app on iOS and have a couple of iterations before porting it to Android (or vice versa).
Remember that Instagram had 30 million users already on iOS before they even launched their Android version.


2. Having Bloated Features

Now that you have picked your app store of choice for the initial launch, it’s important to have a core set of features as your MVP. With your first version, you want to prove the core hypothesis of your app to see if the market is willing to adopt it.
Good user experience is about doing more with less.
If you have an existing web service, don’t try to condense the online experience into the mobile screen. It’s important to rethink your entire user flow and interactions on mobile and not replicate the online experience.
In addition, while it’s important to launch with just a core set of features, remember not to rush development and release a buggy app. Mobile users are unforgiving and will leave 1-star reviews if your app is buggy. This rocky start is very difficult to recover from.


3. Skimming on User Experience

Apple has set the bar with its elegant product design and user experience. You can hand over your iPhone or iPad to a toddler and they will immediately know how to use it.
The mobile user has different expectations than the one on the web. The mobile experience needs to be self-describing and intuitive. While the online user may put up with poor user experience and design, a mobile user will quickly give up on your app if it’s too difficult to use.
In fact, 26% of the apps are only opened once and never use it again, and another 48% are opened 10 times or less. Therefore, you need to have an immediate “wow” factor upon the user launching the app.


4. Trying to be the beta tester for your own app.

“Why have someone else beta test your app when you can do it yourself?”
If you’ve ever asked this question while developing an app, you’ve probably been burned by the outcome. There’s a reason why beta testers are important: They offer valuable outside perspective that will help to catch issues with your app.
It’s not just the bugs that matter, either -- some of these ideas can be crucial for making your app user-friendly. For instance, maybe your in-app purchases aren’t communicated clearly enough, or maybe your use of advertisements is making the entire experience feel a bit jarring. Because you built the app this way, it’s harder for you to be able to pinpoint these high-level flaws.
Use app-analytics tools to see how your testers are using the app. The more people you can have beta test your app outside your own office, the more prepared you’ll be to send your app out into the real world.


5. Marketing After Submitting App

It’s important to start marketing your app as early as possible. Don’t wait until submitting the app to the App Store to start your press outreach. According to the Experts of this domain, You should contact the media around 2-4 weeks before you plan to launch.
Before sending emails, research your favorite technology blogs and look for journalists who have written about a similar app. When sending your emails, make sure to keep them short, personal, and include a few details about what makes your app different.
Include a link to a screenshot or video so the blogger can quickly get a sense of what your app does. At the end of the email ask if they’d like to know more or perhaps try out the app before it goes live.

Friday, 26 May 2017

How to develop a secure Android Application


The Android operating system has lots of built-in security features, such as application sand boxing, protection against buffer and integer overflow attacks, and segregated memory areas for program instructions and data. As a result, simple Android apps that don't perform any file system or networking operations can often be considered secure by default. If you are developing a more complex app, however, it is your responsibility to make it secure and protect the privacy of your users. In this blog, I'm going to list some of the best practices you should follow to build a secure Android app that doesn't leak data or permissions, and is, in general, less vulnerable to malicious apps that might be installed on the user's device.

1. Use Internal Storage for Sensitive Data

Every Android app has an internal storage directory associated with it. Files inside this directory are very secure because they use the MODE_PRIVATE file creation mode by default. This means the files cannot be accessed by any other app on the device. Therefore, it is a best place to store all the sensitive data of your app in the internal storage directory.
To determine the absolute path of your app's internal storage directory, it is recommended that you use the getFilesDir() method. Once you know its path, referencing files inside it is as simple as referencing files inside any other directory.
For example, here's how you could reference a file called myfile.dat in the  internal storage directory of your app:
File myFile = new File(getFilesDir(), "myfile.dat");


2. Encrypt Data on External Storage

The internal storage capacity of an Android device is often limited. Therefore, at times, you might have no choice but to store sensitive data on external storage media, such as a removable SD card.
Because data on external storage media can be directly accessed by both users and other apps on the device, it is important that you store it in an encrypted format. One of the most popular encryption algorithms used by developers today is AES(Advanced Encryption Standard) with a key size of 256 bits.
Writing code to encrypt and decrypt your app's data using the javax.crypto package, which is included in the Android SDK, can be confusing. Therefore, most developers prefer using third party libraries, such as Facebook's Conceal library, which are usually much easier to work with.

3. Validate User Input

On Android, invalid user input doesn't usually lead to security issues like buffer overruns. However, if you allow users to interact with a SQLite database or a content provider that internally uses a SQLite database, you must either rigorously sanitise user input or make use of parameterized queries. Failing to do so makes your data vulnerable to SQL injection attacks.

4. Avoid Asking for Personal Data

User privacy is given a lot of importance these days. Therefore, unless you have a good reason and a very secure infrastructure to collect, store, and transmit personal user information, you must avoid directly asking for it in your apps.
A better approach to user authentication and user profile information look up on Android is through the Google Identity Platform. Google Identity Platform allows users to quickly sign in to your app using their Google account. After a successful sign in through the platform, whenever necessary, your app can easily look up various details about the user, such as the user's name, email address, profile photo, contacts, and more. Alternatively, you could use free services like Firebase that can manage user authentication for you.
If you must handle user credentials yourself, it is recommended that you store and transmit them in the form of secure hashes. The most straightforward way to generate different types of hashes using the Android SDK is by using the MessageDigest class.


Friday, 19 May 2017

Linux : Manage Users

Creating(new user) or deleting existing users from your Linux system is very simple. All you need to do is to login into your system with Administration rights. And follow the below steps...

1. Go to Settings(by clicking the setting icon placed at top-right side of your system).
2. Select “System Settings”.



3. Now Click “User Account”






4. Since the '+' and '-' buttons are disabled initially, so it’s not possible to Add or Remove the users at this stage. In order to do that, we need to unlock the access rights. We can unlock it bu just clicking upon the Unlock button situated at the Top-Right side of this screen.

5. Enter your Admin password.


6. Now you can see the ‘+’ and ‘-’ button has been enabled. Use ‘+’ for adding a new user and ‘-’ for removing an existing user from your system. But before removing a user, make sure that User is selected.

Let’s Add a New User first.

Well, for that, I need to click upon that ‘+’ button. The moment you click the button, you will get the following screen....



The drop down menu here(at the top) is for selecting the user type(Standard or Administrator). Next field asks for the Full Name of the user. The last field(i.e username) will be auto filled.

Now Click the Add button. It will ask for your password once again. Provide your admin password and You are done!!




You can delete the user anytime by clicking the '-' button. 

In the above screen, you can select your option and the selected user will be deleted from your system.

Have a Good Day!! Enjoy..........



Friday, 12 May 2017

Common Development Mistakes


Now a days, development environments are “smart” enough to catch and fix many mistakes that early developers battled with regularly. There are even many different development platforms that easily turn simple static HTML pages into highly interactive applications. The purpose of this blog post is to shed light on some of the common mistakes made in different stages of the web development process. I have touched on a few general topics that are common to virtually all web developers.

#1: Incomplete input validation

Validating user input on client and server side is simply a must do! We are all aware of the sage advicedo not trust user input” but, nevertheless, mistakes stemming from validation happen all too often.
One of the most common consequences of this mistake is SQL Injection.
Most front-end development frameworks provide out-of-the-box validation rules that are incredibly simple to use. Additionally, most major back-end development platforms use simple annotations to assure that submitted data are adhering to expected rules. Implementing validation might be time consuming, but it should be part of your standard coding practice and never set aside.

#2: Authentication without proper Authorization

Before we proceed, let’s make sure we are aligned on these two terms.
Authentication: Verifying that a person is (or at least appears to be) a specific user, since he/she has correctly provided their security credentials (password, answers to security questions, fingerprint scan, etc.).
Authorization: Confirming that a particular user has access to a specific resource or is granted permission to perform a particular action.
Stated another way, authentication is knowing who an entity is, while authorization is knowing what a given entity can do.
Let me demonstrate this issue with an example:
Consider that your browser holds currently logged user information in an object similar to the following:
{
    username:'elvis',
    role:'singer',
    token:'123456789'
}
When doing a password change, your application makes the POST:
POST /changepassword/:username/:newpassword
In your/changepasswordmethod, you verify that user is logged and token has not expired. Then you find the user profile based on the :usernameparameter, and you change your user’s password.
So, you validated that your user is properly logged-in, and then you executed his request thus changing his password. Process seems OK, right? Unfortunately, the answer is NO!
At this point it is important to verify that the user executing the action and the user whose password is changed are the same. Any information stored on the browser can be tampered with, and any advanced user could easily updateusername:'elvis'tousername:'Administrator'without using anything else but built-in browser tools.
So in this case, we just took care ofAuthenticationmaking sure that the user provided security credentials. We can even add validation that/changepasswordmethod can only be executed byAuthenticatedusers. However, this is still not enough to protect your users from malicious attempts.
You need to make sure that you verify actual requester and content of request within your/changepasswordmethod and implement properAuthorizationof the request making sure that user can change only her data.
AuthenticationandAuthorizationare two sides of the same coin. Never treat them separately.

#3: Not optimising bandwidth usage

Most development and testing takes place in a local network environment. So when you are downloading 5 background images each being 3 MB or more, you might not identify an issue with 1 Gbit connection speed in your development environment. But when your users start loading a 15 MB home page over 3G connections on their smartphones, you should prepare yourself for a list of complaint sand problems.
Optimising your bandwidth usage could give you a great performance boost, and to gain this boost you probably only need a couple of tricks. There are few things that many good web developers do by default, including:
  1. Magnification of all JavaScript
  2. Magnification of all CSS
  3. Server side HTTP compression
  4. Optimisation of image size and resolution



Sunday, 30 April 2017

Tips & Tricks - Ubuntu


Hello Friends,

Today, I would like to share some cool and useful tips for all the Ubuntu users. Once you are done with the installation part of the Ubuntu. You are already having a default settings which is pretty awesome actually.  However, there are still many things which you can customize in your Ubuntu system. I am mentioning just few and I am sure there are plenty more. I'll share many more some other time, but as of now, here are the things which you can try.....

Adjust the Launcher Icon Size

Ubuntu DesktopUbuntu includes a launcher on the left of your screen. If it appears that the size of the icons on the launcher is either too small or too big, you can adjust it to the size you like.
  1. Click the Control Gear and select "System Settings".
  2. Click "Appearance" under "Personal".
  3. Under the Look tab, drag the slider of "Launcher Icon Size" to the left for a smaller size, or right for a bigger size.

Auto Hide the Launcher

Depending on the version of Ubuntu you use, the Launcher is set to always either appear or hide on the screen by default. You can change this default setting easily.
  1. Click the Control Gear and select "System Settings".
  2. Click "Appearance" under "Personal".
  3. Under the "Behavior" tab, switch on or off the button of "Auto-hide the Launcher".
To reveal the Launcher temporarily, just press and hold the Super (aka Windows) key, or move your mouse cursor to the far left of the screen. You can adjust the reveal sensitivity with the slider under the "Behavior" tab mentioned above. If it still doesn't work very well, you can adjust the amount of mouse pressure in the following tip.


Make Revealing the Launcher Easier

After auto hiding the Launcher, you can reveal it by moving the mouse cursor to the left edge of the screen. But when you feel that you have to actually knock the mouse cursor against the screen edge hard enough to get the Launcher revealed, then it's better that you adjust the 'mouse pressure' using CompizConfig Settings Manager.
  1. Install CompizConfig Settings Manager from the Ubuntu Apps Directory if the application is not available in your system.
  2. Press Alt+F2 and type ccsm into the box, press Enter to run this program.
  3. Select "Desktop" from the left panel.
  4. Click "Ubuntu Unity Plugin".
  5. Under the "Launcher" tab, adjust the preset value of "Launcher Reveal Pressure" or "Launcher Reveal Edge Responsiveness" where applicable, to lower to make the launcher easier to reveal, or higher to do otherwise, click "Back" and "Close".
Try the Launcher again and enjoy.

Disable Shopping Suggestions

When you do a search from the Dash in Ubuntu, it offers additional search results including shopping suggestions, a feature known as "Shopping Lens" or "Unity Smart Scopes", underneath the local search results by default. If you don't like these suggestions, you can turn them off or back on.
  1. Click the Dash Home icon on the Launcher and click "Filter results" next to the search box.
  2. Uncheck the categories or sources that you want to exclude from the search results.
To turn the online search results permanently, follow these simple steps:
  1. Click the Control Gear and select "System Settings".
  2. Under Personal, select "Security & Privacy".
  3. Under the Search tab, turn off "When searching in the Dash: Include online search results".

Sunday, 9 April 2017

How to make bootable pendrive for ubuntu installation

Hello Everyone !

Today, I would like to share a very basic thing. It's nothing but the process making the pen drive bootable for the ubuntu installation. Gone are the days, when we used to rely upon CD/DVD for any kind of installation. Now, we can use even our pen drive for the installation of an operating systems. Well, if we want to install any operating using the pen drive, Then the very first thing we need to do is to make the pen drive bootable. Aahh...Bootable ?? What’s that ?? Okay, Let’s understand this term closely.

In a layman term, Booting is nothing but the process of starting a system. It means, the moment we press start/power button on our Laptop or Desktop till the system reach to it’s desktop. The whole process involved in between is known as the Booting. The time it takes to accomplish all this, is known as the booting time. Now let’s see how can we make a pen drive bootable, so that we can install the ubuntu using that bootable pendrive. Before proceeding to this step, make sure you have downloaded the ISO(disc image) file of the ubuntu operating system.

Search for “startup disk creator” in your dashboard by typing startup. 



Then open that startup disk creator utility and locate your image file over there by clicking the "Other..." Button. 



Once it’s done, click on Make Startup Disk. That’s it. Now you have the bootable pen drive ready for the installation.

Thursday, 30 March 2017

How to solve WiFi detection problem in Ubuntu


If you are stuck at WiFi detection issue just after a fresh Ubuntu installation, there could be many reasons for that. Most of the time it's because of the missing of the drivers. Though you can certainly install the required driver from the command line. But, it might be a cumbersome task for a newbie. Instead, you can try the most easiest solution given below.


1. Click on the “Search you computer icon” or press the Windows key/logo key/System key on the keyboard.


2. Search for Additional Drivers and Open it.


 3. Go to the Additional Driver Tab, and click on the Apply Change after selecting the option shown in the below picture.


That's it.....!!
Now you should be able to use your WiFi. It worked for me and I am pretty sure it will work for you as well. 



Thursday, 16 March 2017

Holi@HeaderLabs



Hello Everyone!!


Today I am not going to write anything related to Appium, Selenium or any other technical stuffs but the Holi Festival, which we celebrated last week here @HeaderLabs.



Holi is a colorful and most fun-filled festival which is celebrated in the month of March, usually in the latter half of the month. It is a festival, with dancing, singing, and throwing of powder paint and colored water. Numerous legends and stories associated with Holi celebration makes the festival more exuberant and vivid. The most popular one is related to the killing of Holika. The story centers around an arrogant king who wanted everyone in his kingdom to worship him. But his son Prahlad refused and worshiped Lord Vishnu instead. He attempts to kill his son but fails each time. Finally, the king’s sister Holika who is said to be immune to burning, sits with the boy in a huge fire. However, the prince Prahlada emerges unscathed, while his aunt burns to death. Holi commemorates this event from mythology, and huge bonfires are burnt on the eve of Holi as its symbolic representation.




Here @Headerlabs, we celebrate this festival on last Friday with lots of fun and masti. It was my first Holi here @HeaderLabs, and it was a very nice experience. I like the way they celebrate any festival, spacially Holi. First, You can’t be on leave on the day when the celebration is scheduled. Further, You will be the target if it’s your first Holi with them. In fact, there is no difference between the targeted person and the rest. The only difference which I felt is ....you will be thrown first to that muddy place(prepared specially for this festival). That’s it. Once you got that look which Anil Kapoor gets in the movie Nayak...You are done !! Now it’s your turn to replicate your looks to the remaining people. It was too much fun at least for me.

Thursday, 2 March 2017

Appium – There is more than just Clicking and Typing




In my last blog, we discussed how can we perform the actions on the app like clicking or filling the fields, like Login & Password. It was pretty interesting, right? Okay, But there are way more actions that can be performed with an app than what we did last time. In this blog, we are going to see how can we perform other actions such as Dragging, Scrolling over an app using appium.

Let’s start with Dragging, i.e handling the SeekBar. There are some scenarios, where we need to tackle the SeekBar, like to adjust the Volume, Brightness etc. To use this functionality we need to use the method provided by the appium driver called “LongPress()”. Well, that’s not enough. As we are aware of the functionality of the “long press”. It means just pressing the left click button of the mouse(on some object) and not releasing it for while. But that doesn’t drag the SeekBar to a particular position at all. To accomplish that, we definitely need to add some extra stuff. Like, providing the details(i.e., start and end points) to the driver in order to perform the drag operation.

In this example, we are going to see how to modify the range of distance in Tinder App. Say it’s 2 KM at present and I want to modify it to somewhere around 45-50 Km.

Well, to accomplish that, First we need to locate that location at the seek bar and clicking that seek bar. Which can be done by the below code, make sure you are using the correct ID of the element.


WebElement seekbar_distance = driver.findElementById("com.tinder:id/seekBar_distance");
seekbar_distance.click();


Now, we need to drag that pointer(over the seek bar). To do that, we need to make some arrangements. Like, setting the start, end and the distance that has to be cover by that pointer.
Once the pointer reached the desired position, it has to release the click and hence the longPress() is used in the association of two extra methods, “release().perform()”. There will be one more method, i.e., moveTo(int, int), It will actually move/drag that pointer on the seek bar to get the things done.

You can find the below code for the reference. I am sure it will work(on Android).


//Get width of the seekbar
int start = seekbar_distance.getLocation().getX();
int end = seekbar_distance.getSize().getWidth();
//Get height of the seekbar
int y = seekbar_distance.getLocation().getY();

//Select till which position you want to move the seekbar
TouchAction action = new TouchAction(driver);


int moveTo = (int)(end * 0.8); // 0.8 signifies that the 80% percent of the total length
action.longPress(start,y).moveTo(moveTo,y).release().perform();
System.out.println("Successfully moved !!!");



In case, you get any issue wit the code or anything else, shoot your queries or
doubts below in the comment section.

Have a Good Day !!