Search

Just Another Tech Blog

A mind is like a parachute. It doesn't work if it is not open.

Category

Tech News and Gossip

Mobile Automation With Appium, Robot Framework and Android SDK in Ubuntu


Automation becomes an essential part of software testing. For the frequent changes/updates in any software it is necessary to have an fully automated process to test the software to ensure it’s functionalities are working properly. Robot Framework is one of the most handy choice for a well structured automation process of any kind of software or web-application. Mostly, because of it’s built in keywords and reporting features. It’s also highly customizable.

On the other hand, in the era of smart phones and tabs the mobile phone users are increasing dramatically. Therefore, the developers and QA’s need to focus on mobile phone support and testing. So, mobile automation is becoming more important unlike desktop automation. So. here’s the start up article about how can initiate mobile automation.

As the title says we are going to use Robot framework for writing automation scripts and Appium as the server to communicate with the mobile devices. For this tutorial I have used Android virtual Device (AVD) which comes with Android SDK. You can also use real devices as well by making some very minor changes. We have Ubuntu 16.04 LTS for our test environment. You can also setup the test environment on any Windows or MAC OS as well.

Step 1: Installing dependencies

Install Java JDK:

For installing Java JDK there is good instructions in the oracle site, besides that, there are  numbers of tutorial you will find in google search. Here’s what I did to install,

Please note: The JDK version may vary time to time so this might not always right steps for you.

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

sudo update-alternatives --config java

The output will look something like the following. In this case, this is what the output will look like with all Java versions mentioned above installed.

Output:
There are 5 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-6-oracle/jre/bin/java          1         manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          2         manual mode
  3            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  4            /usr/lib/jvm/java-8-oracle/jre/bin/java          3         manual mode
  5            /usr/lib/jvm/java-9-oracle/bin/java              4         manual mode

Press <enter> to keep the current choice[*], or type selection number:

You can now choose the number to use as a default.

Now verify Java installation:

abqu@dhaabquubu:~$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Set JAVA_HOME:

For setting JAVA_HOME open your ~/.bashrc file in any text editor and add the following 2 lines at the end of the file:

nano ~/.bashrc

Add these 2 lines:

Please note: your JAVA_HOME path should be exactly as the output for the sudo update-alternatives –config java command

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
export PATH=${JAVA_HOME}/bin:$PATH

Install Selenium:

Please follow this post for the Selenium installation tutorial: How to Install Python, PIP, Selenium, Chrome and Firefox Driver

Install Robot Framework:

Please follow this post for the Robot Framework installation tutorial: Python Robot Framework Install

Install Robot framework Appium library:

pip install robotframework-appiumlibrary --user

Install Sublime-text-2 editor (Optional):

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

Install homebrew (for linux):

Please follow this post for homebrew installation tutorial: Install Homebrew In Ubuntu 16.04

Install Nodejs (NOT AS ROOT USER), Appium, WD and appium-doctor:

brew update
brew install node
brew link node
npm install -g appium
npm install wd
npm install -g appium-doctor

Now, run appium command to check the appium server is running properly:

abqu@dhaabquubu:~$ appium
[Appium] Welcome to Appium v1.7.1 (REV ce9a10fa47b486859e53c0991c0672c0c2aa8bba)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

Also, run appium-doctor command to check the missing configuration:

abqu@dhaabquubu:~$ appium-doctor
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /home/abqu/.linuxbrew/bin/node
info AppiumDoctor ✔ Node version is 8.7.0
info AppiumDoctor ✔ ANDROID_HOME is set to: /home/abqu/Android/Sdk
info AppiumDoctor ✔ JAVA_HOME is set to: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
info AppiumDoctor ✔ adb exists at: /home/abqu/Android/Sdk/platform-tools/adb
info AppiumDoctor ✔ android exists at: /home/abqu/Android/Sdk/tools/android
info AppiumDoctor ✔ emulator exists at: /home/abqu/Android/Sdk/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

Please note: At this point you may find some ‘x’ sign in the appium-doctor output, it should all be ✔ at the end of this tutorial.

Install Android SDK:

sudo add-apt-repository ppa:maarten-fonville/android-studio

sudo apt update

sudo apt install android-studio

During the installation, the latest Android Studio zip file will be downloaded from Google server. Once the installation is finished, you can open Android Studio from Unity Dash or your preferred app launcher.

android-studio-ubuntu

If the icon didn’t load, then please log out and log back in or use the following command to start Android Studio.

/opt/android-studio/bin/studio.sh

Select whether you want to import previous Android Studio settings or not, then click OK.

ubuntu-android-studio

Then follow the setup wizard. You will prompted to install Android SDK Tools, Android platform tools, Android support library, etc.

android-studio-ubuntu-16.04

Set ANDROID_HOME:

Unlike setting up JAVA_HOME, open the ~/.bashrc file and add the following 2 lines at the bottom of the file then save the file:

export ANDROID_HOME=/home/abqu/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Create Android Virtual Device(AVD)/Emulator:

Please Note: I recommend to use the same device and system image version to use for the first time which has been show in this tutorial. If you use some other device or system image version then you need to change the open application string accordingly in the demo.txt robot script which has been used at the end of this tutorial. Therefore, I suggest, when you gain enough knowledge about appium then you can go for any device and system image.

For creating an AVD open the Android studio, then click on the AVD Manager button.

Selection_043

The AVD manager window will open. Now, follow next button and choose your desire android device and OS version.

Selection_044

Please note: At the very first time the device list will be empty, so click Create Virtual Device… button

First you need to choose a device, here in this tutorial I used Nexus 4.

Selection_045

Now, you need to download the system image/OS, if there is no system image in the Recommended tab then click other two tabs and download them. It will take time to download the system image, so keep patient.

Selection_046

Then follow the Next button and complete the AVD creation.

See the list of AVDs:

Go to ~/Android/Sdk/emulators and run the following commands:

abqu@dhaabquubu:~/Android/Sdk/emulator$ emulator -list-avds
Nexus-4-API-22
Nexus-5X-API-25

The list of AVDs will appear.

The name of the AVDs are very important, so, keep it.

Run the AVDs:

Now run the AVD using following command:

cd ~/Android/Sdk/tools && ./emulator -avd Nexus-4-API-22

Note: Here, you need to replace the Nexus-4-API-22 part with your AVD name.

Install Python six package:

pip install six --user

Run the appium server using appium command.

Now run the appium-doctor command again to check if everything is good.

The output should be like below:

abqu@dhaabquubu:~$ appium-doctor
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /home/abqu/.linuxbrew/bin/node
info AppiumDoctor ✔ Node version is 8.7.0
info AppiumDoctor ✔ ANDROID_HOME is set to: /home/abqu/Android/Sdk
info AppiumDoctor ✔ JAVA_HOME is set to: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
info AppiumDoctor ✔ adb exists at: /home/abqu/Android/Sdk/platform-tools/adb
info AppiumDoctor ✔ android exists at: /home/abqu/Android/Sdk/tools/android
info AppiumDoctor ✔ emulator exists at: /home/abqu/Android/Sdk/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

 

Write Robot scripts and run:

Now, all set up so you can write the automation scripts and run it.

Here is a demo robot file for testing:

*** Settings ***

Library AppiumLibrary

Documentation demo for appium library

Force Tags demo


*** Test Cases ***

test_demo

[Tags] regression

Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=5.1.1 deviceName=Nexus-4-API-22 app=com.android.browser browserName=Browser

Go To Url http://facebook.com
 Wait Until Page Contains Element xpath=//input[@type='email']
 Input Text xpath=//input[@type='email'] test@gmail.com
 Sleep 5

For testing you can save the above code into a file called demo.txt and make it executable then run it from terminal using pybot demo.txt command:

chmod +x demo.txt

pybot demo.txt

Note: You must have the AVD and Appium server running before executing the pybot demo.txt command.

You will see the script will create a browser instance and open the Facebook login page then in the email field it will input ‘test@gmail.com’ email.

If everything goes well you should see the following output in the terminal:

abqu@dhaabquubu:~/Documents/appium-rnd$ pybot demo3.txt 
==============================================================================
Demo3 :: demo for appium library 
==============================================================================
test_demo | PASS |
------------------------------------------------------------------------------
Demo3 :: demo for appium library | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /home/abqu/Documents/appium-rnd/output.xml
Log: /home/abqu/Documents/appium-rnd/log.html
Report: /home/abqu/Documents/appium-rnd/report.html

That’s it!! Happy testing!!!

Advertisements

How to Bypass Adblock Detection on Websites that Bombard You With Ads


Easy One-click Solution to Bypass Ad Block Detection

The easiest way you can bypass ad block detection on a website is by disabling JavaScript using the Site Info option on the browser. Just click on the Site Info icon as shown in the screen shot and disable the JavaScript option.

java-script

Bypass Adblock Using Tamper Monkey Script

If there are more than one website you wish to bypass, than installing anti-adblock killer makes more sense. The UserScript helps you keep your ad-blocker active when you visit a website even when it asks you to disable it. As this is a script, you will have to install Greasemonkey on Firefox or Tampermonkey for Opera or Chrome. Once these add-ons are installed, you will have to download this JS file and add it to the Tampermonkey extension.

Selection_015

Now you do not need to disable the adblocker on any site, instead the JS script will prevent that site’s anti-adblocker script and let you browse the site smoothly.

Happy browsing!!

Source: http://www.guidingtech.com/60376/bypass-ad-block-detection-sites/

Python Robot Framework Install


To install Robot Framework, you need to pre-installed the following items:

  1. Python 2 or 3
  2. Selenium
  3. PIP
  4. PATH setting in Environment Variables

See How to Install Python, PIP, Selenium, Chrome Driver post if you already have not the above things.

Install Robot:

Open CMD as an administrator user.

Type:

pip install robotframework --user
pip install robotframework-selenium2library --user

After completion you can start working on the Robot framework.

You can simply create a .txt file and put the following codes to check the Robot framework is working or not:

*** Settings ***
Library     Selenium2Library
Suite Setup     Go to homepage
Suite Teardown  Close All Browsers

*** Variables ***
${HOMEPAGE}     http://mytestsite/wp-admin
${BROWSER}      chrome
${user}         abc@example.com
${pass}         password

*** Test Cases ***
Open Browser To Login Page
    Input Username    abc@example.com
    Input Password    password
    Submit Credentials

*** Keywords ***
Open Browser To Login Page
    Maximize Browser Window
    Open Browser    ${HOMEPAGE}    ${BROWSER}
    Login Page Should Be Open

Go to homepage
    Open Browser    ${HOMEPAGE}     ${BROWSER}

Input Username
    [Arguments]    ${username}
    Input Text    id=user_login    ${username}

Input Password
    [Arguments]    ${password}
    Input Text    id=user_pass    ${password}

Submit Credentials
    Click Button    xpath=//input[contains(@id, 'wp-submit')]

Save this code in a text file like, demo-robot.txt

Now from CMD or terminal type

pybot demo-robot.txt

It will run the script and generate the detail report, log file and other necessary output.

You can also save the file as robot file like, debo-robot.robot

It that case you need to add “C:\Python27\Lib\site-packages\robot” in your Environment Variable.

Now type the following code to run the robot script:

robot demo-robot.robot

Please Note: If you are using any IDE like Pycharm, some notification will appear after installing Robot framework, which will say that there are some plugins for Robot, do you want to install it or not. In that case you should install it in the IDE.

10 Common Bad Habits Of Bloggers


source: 10 Common Bad Habits Of Bloggers.

“Pobody is Nerfect”. This rule applies to bloggers too who work hard daily to explore new things on the web and give new information through their blog. But lots of bloggers do mistakes in their early stage of blogging. It’s hard and rare to accept those mistakes. I want to explore some common bad habits of Bloggers which results in loss of productivity. One should avoid these habits.

Common Bad Habits

CREDIT: FENSTERBME

List of common bad Habits:

Though, I’m writing this post by keeping Bloggers in mind, but some of these bad habits, applies to normal Internet users too. So, you can start working on them and change your habits to be a better person.

1. Social media addiction

Social media is good to bring traffic on blog. But involving too much in social media and forget your original work (generating content) is not good for your blog. Try to avoid too much social media involvement. Remember that content is the king and it is responsible for traffic. Social media is secondary thing.

2. Work from bed

There are many bloggers who work from bed and they stick to this habit. If you work 1 hour then it would not a serious issue but if you are giving 7 to 10 hours daily for your work then it is a serious matter. For those people we already give some tips to  setup office at home for professional blogging.

3. Never proofread articles

I already told you that proofreading article is a best way to find your errors inside the post. Try to read two or three times to find mistakes of your post. Also ensure that don’t start editing your post while writing it.

4. Giving current news

If your blog has some decent traffic then providing breaking news is not incorrect because your post will get a good exposure. But if your blog gets a fever traffic then it is not a good idea to show current news through your blog. Remember, there are several good blogs which are doing this work properly and efficiently.

5. Too much coffee

Coffee is good when you take breaks during your work. But consuming too much coffee (nicotine) is not good for your health and for your work. It will effect your mind and overall productivity.

6. Working in cluttered space

Either you are working from home or you work in office you need to take care of one thing that your work space should be separated from rest of your home. If you are making your bed room as your office then make sure that your room should be spacious, having windows for natural lights and free from any disarrangement.

7. Being non social

My friends always complain that I never find too much time for them. I involve in my work so much that I never found time for any social activities which is actually not good. I am trying to improve my habit. I generally take break from my work (on Sunday) and plan movies and dinner with friends.

8. Working late night

Bloggers love to work late night. Probably this is because in night they found no disturbance. They free to do all their pending work in silence. But I suggest you to work in day time. Try to wake early morning and start working with fresh mind. You don’t need to follow strict 9 to 6 office time but completing all work early in a day would invite some relief to you.

9. Drinking habit

We came up with post Why Bloggers Drink and How to Avoid Drinking in which we discussed about rise of drinking and smoking culture in bloggers. We also give ideas to get rid of this habit.

10. No vacations

Working all the time causes lots of strain inside our brain. It increases stress level and you may lose your interest from your work. Vacation give us opportunity to recharge and regenerate our power. Try to schedule your post in WordPress and fly off somewhere. In this period do not do any work instead of checking important mail and replying to clients.

These are some common bad habits of bloggers. Do you want to add something more in the list? Add them through your valuable comments.

Read more: http://www.shoutmeloud.com/10-common-bad-habits-of-bloggers.html#ixzz2BVtWAZqm
Under Creative Commons License: Attribution No Derivatives

Perform while loop in the Selenium IDE


Below is an example of while loop in selenium IDE:

drupal_test
getEval array=new Array(2);
getEval index=0;
store javascript{array.length} x
gotoIf ${x}>19 target_2
while index<array.length
label target_1
open /drupal-7.14/?q=user/register
randomText id=edit-name
randomEmail id=edit-mail
type id=edit-field-age-und-0-value 24
type id=edit-field-first-name-und-0-value Jack
type id=edit-field-last-name-und-0-value sparrow
type id=edit-field-sex-und-0-value Male
clickAndWait id=edit-submit
waitForText css=div.messages.status Status message Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, a welcome message with further instructions has been sent to your e-mail address.
verifyTextPresent Status message Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, a welcome message with further instructions has been sent to your e-mail address.
getEval index++;
endWhile
label target_2
echo Either completed or you attempted to create more then 20 user accorunt, are you sure? To continue change the value in line 5.

Customization:

  • In this script I use a limit, for this maximum 19 users can create using this script. One can change the limit easily by customizing line number 4.

Create a free website or blog at WordPress.com.

Up ↑