Lets start creating our own Ruby Appium Test Automation Framework

Lets start creating our own Ruby Appium Test Automation Framework

Mobile testing is growing as most of the application are moving toward mobile platform, like Facebook, google, etc.

These applications should be tested before releasing to public domain. Test automation of these application testing is a must. Appium is used widely in mobile application test automation. Today in this article I will teach you'll how to create our own Ruby mobile test automation framework.

First of all we need to install Ruby in our machine.

You need to also install Android SDK tools and create environment path for tools and plat-form tools.

Next I created the page classes in Ruby capturing the page elements of the EriBank application via UI Automation Viewer.

Main Screen

class HomePage
	

	  attr_reader :driver
	
	  def initialize(driver)
	    @driver = driver
	
	  end
	
	  def clickMakePayment()
	    @driver.find_element(:id,'com.experitest.ExperiBank:id/makePaymentButton').click()
	  end

	end

Login Screen

class LoginPage
	
	  userName        =  'com.experitest.ExperiBank:id/usernameTextField'
	  password        =  'com.experitest.ExperiBank:id/passwordTextField'
      loginBtn        = 'com.experitest.ExperiBank:id/loginButton'

	  attr_reader :driver
	
	    def initialize(driver)
	      @driver = driver
	
	    end
	
	    def setUserName(user_name)
	      @driver.find_element(:id,userName).send_keys(user_name)
	    end
	    def setPassword(passwords)
	      @driver.find_element(:id,password).send_keys(passwords)
	    end
	  def clickLogin()
	    @driver.find_element(:id,loginBtn).click()
	  end

	  end

Make Payment Screen

class MakePayment
	
phoneText = 'com.experitest.ExperiBank:id/phoneTextField'
nameText = 'com.experitest.ExperiBank:id/nameTextField'
countryText = 'com.experitest.ExperiBank:id/countryTextField'

	  attr_reader :driver
	

	  def initialize(driver)
	    @driver = driver
	

	  end
	

	  def setTelePhone(telephone)
	    @driver.find_element(:id,phoneText).send_keys(telephone)
	  end
	  def setName(name)
	    @driver.find_element(:id,nameText).send_keys(name)
	  end
	  def setCountry(country)
	    @driver.find_element(:id, countryText ).send_keys(country)
	  end

	end

For data driven I have used roo library for Excel data driven

gem install roo



require 'roo'
	

	def read_excel (filePath, sheetName, row, col)
	  xlsx = Roo::Spreadsheet.open(filePath)
	  return xlsx.sheet(sheetName).cell(row,col)
	end

Next I implemented the reporting for the mobile test automation framework. Here I have used HTML report generation.

def get_time_name
	  $time=Time.now
	  $time_name="#{$time.hour.to_s}-#{$time.min.to_s}-#{$time.sec.to_s}-#https://www.dhirubhai.net/redir/general-malware-page?url=%7B%24time%2eday%2eto_s}-#{$time.mon.to_s}-#{$time.year.to_s}"
	  $result_date = "#https://www.dhirubhai.net/redir/general-malware-page?url=%7B%24time%2eday%2eto_s}-#{$time.month.to_s}-#{$time.year.to_s}"
	end
	def create_report
	  get_time_name
	  @result_file_name="Report"+"-"+$time_name
	  @full_file_name="Results/#{@result_file_name}.html"
	  $report=File.open(@full_file_name,'w')
	end
	def insert_head_title(title)
	  $report.puts "<html><head>
	<title> #{title} </title>
	</head>"
	end
	def start_table
	  $report=File.open(@full_file_name,'a')
	  $report.puts "<table border=1>
	<tr>
	<th>Test Case Name</th>
	<th>Test Case Description</th>
	<th>Browser Name</th>
	<th>Result</th>
	<th>Remarks</th>
	</tr>"
	  $report.close
	end
	def insert_reportname_date(name,date)
	  $report.puts "<body bgcolor='#5CB3FF'>
	<p align='left' size=2>
	<b><img src='https://encrypted-tbn1.google.com/images?q=tbn:ANd9GcQB0l0xnGOHuRPFMMMi-OVg39nfAU1Ogvxr7Okk7DD8ZpqlMF9r'></img> </b>
	</p>
	<p size=12>
	<center> <b><u>#{name} </u></b></center>
	</p>
	<p align='right' size=12>
	<b>Date: #{date} </b>
	</p>"
	  $report.close
	end
	def report_row(*details)
	  $report=File.open(@full_file_name,'a')
	  name=details[0]
	  desc=details[1]
	  browser=details[2]
	  result=details[3]
	  reason=details[4]
	  if result.downcase == "pass"
	    $report.puts "<tr>
	<td>#{name}</td>
	<td> #{desc}</td>
	<td> #{browser} </td>
	<td bgcolor='green'>#{result}</td>
	<td>#{reason}</td>
	</tr>"
	  else
	    $report.puts "<tr>
	<td>#{name}</td>
	<td> #{desc}</td>
	<td> #{browser} </td>
	<td bgcolor='red'>#{result}</td>
	<td>#{reason}</td>
	</tr>"
	  end
	  $report.close
	end
	def close_table
	  $report=File.open(@full_file_name,'a')
	  $report.puts "</table></br>"
	  $report.close
	end
	def summary_report(overall,passed,failed)
	  $report_overall=overall
	  $report_pass=passed
	  $report_fail=failed
	  $report=File.open(@full_file_name,'a')
	  $report.puts "<p> <b>Total Test cases : #{$report_overall} </b></p>
	<p> <b>Passed : #{$report_pass} </b></p>
	<p> <b>Failed : #{$report_fail} </b></p>
	</body>
	</html>"
	  $report.close

Now we are completed with the framework and I was able to run the test case in real mobile device.

Test Case

require 'rubygems'
	require 'appium_lib'
	require_relative './Pages/LoginPage'
	require_relative './Pages/HomePage'
	require_relative './Pages/MakePaymentPage'
	require_relative './Utility/excelReader'
	require_relative './report'
	desired_caps = {
	    caps:  {
	        platformName:  'Android',
	        deviceName:    'AVY9KA9631900412',
	

	        app: 'com.experitest.ExperiBank',
	        appActivity: '.LoginActivity'
	    }
	}
	

	@appium_driver = Appium::Driver.new(desired_caps)
	@appium_driver.start_driver
	create_report
	insert_head_title ("Report for the Ruby Appium Automation Framework - Kushan Amarasiri")
	insert_reportname_date("My Test Report",$result_date )
	start_table
	login = LoginPage.new(@appium_driver)
	login.setUserName(read_excel("./Data/data.xlsx", "Sheet1",2,1))
	login.setPassword(read_excel("./Data/data.xlsx", "Sheet1",2,2))
	login.clickLogin
	report_row("Logged into the application","Eri Bank App","PASS", "Eri Bank App")
	home = HomePage.new(@appium_driver)
	home.clickMakePayment
	makePayment = MakePayment.new(@appium_driver)
	makePayment.setTelePhone(read_excel("./Data/data.xlsx", "Sheet1",2,3))
	makePayment.setName(read_excel("./Data/data.xlsx", "Sheet1",2,4))
	makePayment.setCountry(read_excel("./Data/data.xlsx", "Sheet1",2,5))
	report_row("Made Payment","Eri Bank App","PASS", "Eri Bank App")



Jasmine Nabila Novel

Quality Assurance Engineer at DOKU, PT NUSA SATU INTI ARTHA

5 年
回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了