Sunday 20 November 2016

How to Install Appium on Ubuntu

In this post we will step by step install appium on Ubuntu System. So lets get to the point and start installation.


Note -Appium throws error if you install via SUDO so install Appium via npm


1. To install Appium via an npm you need  node.js and npm 0.12 or greater.


2. To install node.js and appium without sudo we use linuxbrew.

3. To install linuxbrew these are the dependencies

    Ruby 1.8.6 or newer
    GCC 4.2 or newer
    Git 1.7.12.4 or newer
    Linux 2.6.16 or newer
    64-bit x86 or 32-bit ARM platform

4. Install Ruby using below command

sudo apt-get install build-essential curl git m4 python-setuptools ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev


5. Install Linux Brew using below command

ruby -e “$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"



6. Set Path for brew

first type sudo gedit.bashrc in terminal  and copy the below in the .bashrc file.export
 
PATH="$HOME/.linuxbrew/bin:$PATH"exportMANPATH="$HOME/.linuxbrew/share/man:$MANPATH"export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"



7 .Install Node:Open new terminal and copy the command and press enter
brew update
brew install node
brew link node
 


8.Finally Install Appium using below command
npm install -g appium

9.Let's Check if the installation is successfull. Open the terminal and type "appium" and hit enter.You should see something like this in the terminal

info: Welcome to Appium v1.4.12(REV 8db2d00b9afcf2c50a09a80a2e8d56b05a902caf)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug

Saturday 19 November 2016

Database Testing with Appium & JDBC



Appium is limited to testing your mobile applications. To use Appium for Database Testing you need to use the JDBC ("Java Database Connectivity").JDBC (Java Database Connectivity) is a SQL level API which allows you to execute SQL queries using java code . JDBC is used for enabling  connectivity between the Java Programming language and a wide range of databases. 

To test with database we need to learn how to connect with database first then how to execute queries followed by how to process the results.

Video Tutorial -



1. Connect to Database -

In order to make a connection to the database the syntax is as per given below and after connection setup you also need to load the JDBC Driver.


Connection con = DriverManager.getConnection(dbUrl,username,password);

Class.forName("com.mysql.jdbc.Driver"); 

Where,
  • Userid is the username configured in the database
  • Password of the configured user
  • URL is of format jdbc:< dbtype>://ipaddress:portnumber/db_name"

2.  Execute Queries -

Once connection is made, you need to execute queries.You can use the Statement Object to send queries. First Create Statement and once the statement object is created use the executeQuery method to execute the SQL queries.

Statement stmt = con.createStatement();

ResultSet rs=stmt.executeQuery(select * from employee); 

 

3. Process Results -

As in above example we have seen that after query execution the result is stored in  ResultSet Object. with this class object we can perform loads of actions to process an test the results as per our requirement.
  • String getString() - get the string type data from ResultSet.
  • int getInt() - get the integer type data from ResultSet.
  • double getDouble() - get the double type data from ResultSet.
  • Date getDate() - get the date type data from ResultSet.
  • boolean next() - move to next record in the ResultSet.
  • boolean previous() - move to previous record in the ResultSet.
  • boolean first() - move to first record in the ResultSet.
  • boolean last() - move to last record in the ResultSet.
  • boolean absolute(int rowNumber) - move to perticular record in the ResultSet.
 

Friday 18 November 2016

Implicit & Explicit Wait with Appium

As we have all faced that we need to wait for loading in mobile application.Mostly we use Thread.sleep() but it is not advised to use this as we can predict the exact time to wait. Appium provides Implicit wait and Explicit wait feature. We can use implicit wait when we know the exact time to wait and Explicit wait when we don't know the exact time to wait but we need to wait until any mobile element is visible.
 

In this post we will see two types of Waits which are widely used in Appium-

Video -  

 

1.Implicit Wait.
2.Explicit Wait.

Implicit & Explicit Wait with Appium
Wait with Appium

1.Implicit Wait

Implicit Wait means informing appium web driver to wait for specific amount of time and if the web element is not visible after waiting for that specific point then throw "No such Element found Exception". 
Check out the Example given below to understand how to use Implicit wait in Appium Test Case.In below Test case we will add a wait for 30 seconds after opening the browser so that that the page is gets loaded completely.As we implicitly specify the time and Time Unit this is called as implicit wait.
method implicitlywait() accepts 2 parameters first one is time value and second one is time unit like days,hours,minutes,seconds,milliseconds etc.

driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
 

2. Explicit Wait -

In Explicit wait along with wait time we also provide the wait condition. It will wait till the condition or the maximum wait time provided before throwing the Exception"ElementNotVisibleException".
We can say that Explicit wait is intelligent wait as it waits dynamically for specified condition. Check out the below test case example for using Appium Explicit wait.First We need to instantiate WebDriverWait  wait object with Web Driver Reference and time frame in seconds.
Then we can use until() method for passing Expected Wait Condition and use it in our test case for waiting until the element is visible on the screen.Here we are using  visibilityofElementLocated() condition.To find out about other conditions type ExpectedConditions in eclipse IDE and press cltr+space bar and you will get the list of conditions which you can use in with Explicit Wait.


WebDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("about_me")));      


With this you can get rid of test case failure due to wait issues.

I hope you find this post useful. fallow me on facebook or google plus to get latest post updates. Happy Testing.