Ruby, Appium, Android, Rspec, Pry, Automation Testing
Total Page:16
File Type:pdf, Size:1020Kb
GKTCS Innovations Pvt. Ltd. Ruby, Appium, Android, Rspec, Pry, Automation Testing Surendra Panpaliya Director, GKTCS Innovations Pvt. Ltd, Pune. 16 + Years of Experience ( MCA, PGDCS, BSc. [Electronics] , CCNA) Director , GKTCS Innovations Pvt. Ltd. Pune [ Nov 2009 – Till date ] IT Manager and Consultant at Rolta India Ltd, Mumbai [ April 2007 – Oct 2009 ] Associate Professor at Sinhgad Institute , Pune [Jan 2002 – April 2007] Instructor , ITM Bangalore [ May 2000 – Jan 2002 ] Project Trainee, DSYS Software Group, Bangalore [ Jan 1999 to April 2000] Skills ❑ Ruby, Rail,Appium, Python, Jython, Django, Android , PHP, LAMP ❑ Data Communication & Networking, CCNA ❑ UNIX /Linux Shell Scripting, System Programming ❑ CA Siteminder, Autosys, SSO, Service Desk, Service Delivery Author of 4 Books National Paper Presentation Awards at BARC Mumbai 2 Agenda ( Day 1) • Introduction • Ruby installation • What’s New in Ruby • Ruby Data Types/ Data Structure • Ruby Comparison with Other Language ( Java/C+ + ) • Ruby Demo Script • Appium Introduction • Appium Installation Setup • Discussion 3 Agenda ( Day 2) • Android adb commands • About Android AVD • About Appium Architecture • Appium Features • Using Appium to test Android Emulator/ Physical Device • Writing Ruby Scripts to Automate app through Appium • Discussion 4 Agenda ( Day 3) • Manual Testing to Automation using Ruby • Execute and Automate Test • Rspec Introduction • Rspec Installation • Rspec for Automation • Rspec Demo • Pry Introduction • Debugging using Pry • Pry Demo • Discussion 5 Introduction • What is Ruby? • What is difference between Scripting language and Programming Language? • What’s New in Ruby? • Ruby Installation • irb • Ruby Script execution. 6 Appium Introduction What is Appium? • Appium is a mobile UI testing framework supporting cross-platform testing of native, hybrid and mobile-web apps for iOS and Android. • Appium enables you to execute your tests on mobile device irrespective of the device OS. • Framework is basically a wrapper that translates Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type. 7 Appium Introduction • What languages can I use to write the TestScripts? • You can write TestScripts in any language that Selenium WebDriver dependency is available for. This includes C#, Closure, Java, JavaScript with Node.js, Obj-C, Perl, Python, Ruby. • Appium is an open-source tool that can be used to automate your mobile applications. Just like the Selenium WebDriver - which is an open-source tool used to automate web browsers. • Appium is an automation library used to drive your mobile applications, and even the web browser within the mobile simulator, emulator or real device. 8 Advantages of using Appium • It allows you to write tests against multiple mobile platforms using the same API. • You can write and run your tests u s i n g a n y l a n g u a g e o r t e s t framework. • It is an open-source tool that you can easily contribute to. 9 Limitations using APPIUM • Appium does not support testing of Android Version lower than 4.2 • Limited support for hybrid app testing. eg: not possible to test the switching action of application from the web app to native and vice- versa. • No support to run Appium Inspector on Microsoft Windows. 10 APPIUM PHILOSOPHY • Appium was designed to meet mobile automation needs according to a philosophy outlined by the following four tenets: • You shouldn’t have to recompile your app or modify it in any way in order to automate it. • You shouldn’t be locked into a specific language or framework to write and run your tests. • A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs. • A mobile automation framework should be open source, in spirit and practice as well as in name! 11 APPIUM Architecture APPIUM Architecture • Appium runs on real devices and emulators. • It takes the Selenium commands from your test code and translates them into a readable format for UIAutomator, using the WebDriver JSON Wire Protocol. • WebDriver (aka "Selenium WebDriver") specifies a client- server protocol (known as the JSON Wire Protocol). • Given this client-server architecture, a client written in any language can be used to send the appropriate HTTP requests to the server. • The client libraries are simply HTTP clients and can be mixed into your code any way you please. • In other words, Appium & WebDriver clients are not technically "test frameworks" -- they are "automation libraries". Appium Concepts • Client/Server Architecture • Appium is at its heart a webserver that exposes a REST API. It receives connections from a client, listens for commands, executes those commands on a mobile device, and responds with an HTTP response representing the result of the command execution. • The fact that we have a client/server architecture opens up a lot of possibilities: we can write our test code in any language that has a http client API, but it is easier to use one of the Appium client libraries. • We can put the server on a different machine than our tests are running on. • We can write test code and rely on a cloud service like Sauce Labs to receive and interpret the commands. Appium Concepts • Session • Automation is always performed in the context of a session. Clients initiate a session with a server in ways specific to each library, but they all end up sending a POST /session request to the server, with a JSON object called the 'desired capabilities' object. • At this point the server will start up the automation session and respond with a session ID which is used for sending further commands. Appium Concepts • Desired Capabilities • Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the Appium server to tell the server what kind of automation session we're interested in starting up. • There are also various capabilities which can modify the behavior of the server during automation. • For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android one. Or we might set the safariAllowPopups capability to true in order to ensure that, during a Safari automation session, we're allowed to use JavaScript to open up new windows. • http://appium.io/slate/en/master/?ruby#appium-server- capabilities • Appium Server • Appium is a server written in Node.js. It can be built and installed from source or installed directly from NPM. Appium Concepts • Appium Clients • There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium's extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client. You can view the full list of libraries here. • Appium.app, Appium.exe • There exist GUI wrappers around the Appium server that can be downloaded. These come bundled with everything required to run the Appium server, so you don't need to worry about Node. They also come with an Inspector, which enables you to check out the hierarchy of your app. This can come in handy when writing tests. workflow workflow Architecture workflow • We have a UIAutomator/Selendroid in place of Apple instruments and bootstrap.jar in place of the bootstrap.js file. • Appium supports Android versions greater than or equal to 17; for earlier versions, it uses the Selendroid framework. • When we execute the test scripts, Appium sends the command to the UIAutomator or Selendroid on the basis of the Android version. • Here, bootstrap.jar plays the role of a TCP server, which we can use to send the test command in order to perform the action on the Android device using UIAutomator/Selendroid. Prerequisite • ANDROID SDK • JDK (Java Development Kit) • TestNG • Eclipse • Selenium Server JAR • Webdriver Language Binding Library • APPIUM For Windows • APK App Info On Google Play • Node.js (Not Required - Whenever Appium server is installed, it by default comes with "Node.exe" & NPM. It's included in Current version of Appium.) Installation Steps • 1. Install Java JDK • Edit your .bash_profile with "." before to update your environment to point correctly to java • $ cd • $ open -a TextEdit .bash_profile • If the file doesn't exist you will get the error: • The file /Users/???/.bash_profile does not exist. • Then • $ touch .bash_profile • $ open -a TextEdit .bash_profile Installation Steps • Insert into .bash_profile and save • export JAVA_HOME=$(/usr/libexec/java_home) • Restart the terminal to include the new configurations. In terminal type: • $ source .bash_profile • or just quit and reopen terminal • To test in terminal • $ java -version • For Older Mac OSX • Same as above but hardcode path and replace ?.?.? with your version • export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/?.?.?.jdk/Contents/Home • echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home Installation Steps Surendras-MBP:~ SurendraMac$ vim .bash_profile export JAVA_HOME=/Library/Java/JavaVirtualMachines/ jdk1.8.0_60.jdk/Contents/Home export ANDROID_HOME=/Users/SurendraMac/Library/Android/sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH export PATH=$JAVA_HOME/:$PATH # added by Anaconda 2.3.0 installer export PATH="/Users/SurendraMac/anaconda/bin:$PATH" Installation Steps • 2. Install Android Studio/SDK • Install all SDK tools and emulators • Select "Configure" • Select "SDK Manager" • Install all available packages Installation Steps • 2. Install Android Studio/SDK Installation