This is the second part of the series "Test automation on Android using Appium, C# and MSTest". If you missed the first part, Click here.
Open Visual Studio Ultimate (2010 or above) (I am using VS2012)
Create a unit Test project.
Install "Appium Web Driver" and "Selenium WebDriver" using NuGet package manager. (The easiest way)
If you don't want to use NuGet package manager, you can manually download appium dot net driver and selenium web driver c# libraries and add them to your solution
Your reference section should look like this.
Now open your UnitTest1.cs file and add following namespaces in your using section
Now watch your android phone, A calculator window will open on your android phone, button 2 will be tapped, then button + , then button 4 and then button =.
After that result will show 6 and your test case should ideally be passed. Make sure your Appium server is running. Appium window will show you all the logs.
Congratulations, you have just written your first automated test case in Appium and it is running on a real android device.
Coding Time
Now it is time to code.Open Visual Studio Ultimate (2010 or above) (I am using VS2012)
Create a unit Test project.
Install "Appium Web Driver" and "Selenium WebDriver" using NuGet package manager. (The easiest way)
If you don't want to use NuGet package manager, you can manually download appium dot net driver and selenium web driver c# libraries and add them to your solution
Your reference section should look like this.
Now open your UnitTest1.cs file and add following namespaces in your using section
using System; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android; using OpenQA.Selenium.Remote;In your [TestInitialize] section, write this code.
[TestInitialize] public void BeforeAll() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("device", "Android"); capabilities.SetCapability(CapabilityType.Platform, "Windows"); capabilities.SetCapability("deviceName", "H30-U10"); capabilities.SetCapability("platformName", "Android"); capabilities.SetCapability("platformVersion", "4.3"); capabilities.SetCapability("appPackage", "com.android.calculator2"); capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator"); driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180)); }in your [TestMethod], write this code
[TestMethod] public void TestCalculator() { var two = driver.FindElement(By.Name("2")); two.Click(); var plus = driver.FindElement(By.Name("+")); plus.Click(); var four = driver.FindElement(By.Name("4")); four.Click(); var equalTo = driver.FindElement(By.Name("=")); equalTo.Click(); var results = driver.FindElement(By.ClassName("android.widget.EditText")); Assert.AreEqual("6", results.Text); }The complete code should look like this.
using System; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android; using OpenQA.Selenium.Remote; namespace AppiumSample { [TestClass] public class UnitTest1 { public AndroidDriver driver; [TestInitialize] public void BeforeAll() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("device", "Android"); capabilities.SetCapability(CapabilityType.Platform, "Windows"); capabilities.SetCapability("deviceName", "H30-U10"); capabilities.SetCapability("platformName", "Android"); capabilities.SetCapability("platformVersion", "4.3"); capabilities.SetCapability("appPackage", "com.android.calculator2"); capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator"); driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180)); } [TestCleanup] public void AfterAll() { driver.Quit(); } [TestMethod] public void TestCalculator() { var two = driver.FindElement(By.Name("2")); two.Click(); var plus = driver.FindElement(By.Name("+")); plus.Click(); var four = driver.FindElement(By.Name("4")); four.Click(); var equalTo = driver.FindElement(By.Name("=")); equalTo.Click(); var results = driver.FindElement(By.ClassName("android.widget.EditText")); Assert.AreEqual("6", results.Text); }To run this test case, click on Test Menu > Windows > Test Explorer. A window will open on your left and it will list down the test cases. Select your desired test case and click run.
Now watch your android phone, A calculator window will open on your android phone, button 2 will be tapped, then button + , then button 4 and then button =.
After that result will show 6 and your test case should ideally be passed. Make sure your Appium server is running. Appium window will show you all the logs.
Congratulations, you have just written your first automated test case in Appium and it is running on a real android device.
Some Explanation
Most of the code is self explanatory. But I want your attention on these two lines.capabilities.SetCapability("appPackage", "com.android.calculator2"); capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator");For every application you want to test, you must know its package name and app activity name. So to know about these attributes, you need to download a little android app on your phone. It is called apkInfo. It will show you the package name and activityname of any android app installed on your phone. Just pass these parameters here and that app will launch on your phone by automation code.
Hello Saad,
ReplyDeleteI tried following all the steps you mentioned in both articles but i'm facing one issue.
Issue: > error: Logcat capture failed: spawn "C:\Android\adb.exe" ENOENT
I tried verifying my path but no luck all looks good , can you please help me?
> info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : device, platform
> info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
> info: [debug] Creating new appium session b3b8bed8-28de-4403-9da5-33b1c3b3f35d
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_45
> info: [debug] Checking whether adb is present
> warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
> info: [debug] executing cmd: where adb
> info: [debug] Using adb from C:\Android\adb.exe
>
> warn: No app capability, can't parse package/activity
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: "C:\Android\adb.exe" devices
> info: [debug] 1 device(s) connected
> info: Found device ba1fb281
> info: [debug] Setting device id to ba1fb281
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: "C:\Android\adb.exe" -s ba1fb281 wait-for-device
> info: [debug] executing cmd: "C:\Android\adb.exe" -s ba1fb281 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> error: Logcat capture failed: spawn "C:\Android\adb.exe" ENOENT
> info: [debug] Stopping logcat capture
> info: <-- POST /wd/hub/session - - ms - -
> undefined
Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!
DeleteETL Testing training in chennai| SAP MM training in chennai | Informatica training in chennai
Great Article
DeleteFinal Year Project Domains for CSE
Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Great Article
DeleteFinal Year Projects for CSE in Python
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in
Chennai
Nice one..
ReplyDeleteYour app success depends on its uniqueness, intuitive design, and rich set of features and so on.
ReplyDeletehttp://www.showboxdownloadsapp.com/
ReplyDeleteWhen it comes to gaming consoles, there is always a big fight between Sony's Playstation and Microsoft's XBox. Now this rivalry is going to increase even more because Microsoft is getting ready to launch it's next console, the Xbox 2. You can check out all the details from my site here Xbox 2
Can you please give example of testing Hybrid app using Appium C#.
ReplyDeleteTest Automation on Android using Appium, C# My sincere thanks for sharing this post Please Continue to share this post
ReplyDeleteSoftware Testing Training in Chennai
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
Deletenice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
ReplyDeletesoftwaretesting training in chennai
Great content thanks for sharing this informative blog which provided me technical information keep posting. Software Testing Training in Chennai | Selenium Training in Chennai
ReplyDeleteThis is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.I really like this topic.
ReplyDeletePython Online Training
Learn Python Online
nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge about this. so keep on sharing such kind of an interesting blogs.
ReplyDeletepython training in marathahalli
nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
ReplyDeleteselenium training in chennai
Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.
ReplyDeleteWeb Designing Training Institute in Chennai | DotNet Training Institute in Chennai | Java Training Institute in Chennai
Thanks a lot for sharing this with all of us, I like it and we can communicate. Do you need buy app ratings and reviews. To boost app ranking and double app downloads now.
ReplyDeleteWell Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
ReplyDeleteAndroid Project Center in Chennai | Android Project Center in Velachery
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeletejava training in bangalore
java training in bangalore
Thanks for your informative article. Your post helped me to understand the future and career prospects. Keep on updating your blog with such awesome article.
ReplyDeleteME/M.Tech Project Center in Chennai | ME/M.Tech Project Center in Velachery
Thank you for this great post! It has long been incredibly beneficial. I wish which you will carry on posting your information with us. @ Orthopedic Doctors in Visakhapatnam
ReplyDeleteGoogle makes it easier for developers to market their apps by having Android Market pre-installed on most Android devices and allows people to choose from apps published by many different developers.Download ShowBox APK
ReplyDeletegamekillerdownloads.com
ReplyDeleteThe information you share is very useful. Thank you for the valuable information.
ReplyDeleteMy Website
nice post thanks for sharing
ReplyDeleteselenium training centers in Marathahalli
best software testing training institutes in Marathahalli with placements
automation testing courses in Marathahalli
selenium testing course in Marathahalli
software testing institutes in Marathahalli
selenium training in Marathahalli
best selenium training in Marathahalli
selenium course in Marathahalli
Thanks for sharing this information
ReplyDeleteselenium training centers in Marathahalli
best software testing training institutes in Marathahalli with placements
automation testing courses in Marathahalli
selenium testing course in Marathahalli
software testing institutes in Marathahalli
selenium training in Marathahalli
best selenium training in Marathahalli
selenium course in Marathahalli
sobha dream gardens
ReplyDeleteGBWhatsapp apk Download Latest Version 2018. Download Latest GB Whatsapp for Use 2 Whatsapp in One Mobile. GBWhatsApp APK
ReplyDeleteThank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
ReplyDeleteJava Training in Chennai
Java course in Chennai
Hadoop Training in Chennai
Python Training in Chennai
Java Training in Porur
Java Training in Adyar
Java Training in Tnagar
Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign
ReplyDeleteapk download
The free application always provides the service of navigation, community, weather, music and so on. The service of document and the hardware management should be paid.gerald winata gozali
ReplyDeleteThanks for your sharing
ReplyDeleteData Science Training in Chennai
DevOps Training in Chennai
Hadoop Big Data Training
A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
ReplyDeleteOracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Brilliant blog I visit this blog it's incredibly awesome. Curiously, in this blog content formed doubtlessly and sensible. The substance of information is helpful.
ReplyDeleteOracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Oracle Fusion Financials Online Training
Oracle Fusion HCM Training In Hyderabad
Oracle Fusion SCM Training In Hyderabad
Oracle Fusion Financials Training In Hyderabad
oracle fusion financials classroom training
Oracle Fusion HCM Classroom Training
oracle cpq online training / Oracle CPQ Class Room Training
Oracle Taleo Online Training
GBWhatsApp has group video calling feature and many privacy options, With GB WhatsApp you can use two applications of WhatsApp Plus in same android device. https://whatsopp.net/download-gbwhatsapp-apk-latest-version/
ReplyDeleteUse dual account with GBwhatsapp Latest Application With free of cost. Gbwhatsapp Apk
ReplyDeleteGood information. Mathway App is the best App to have for simple to complex math solutions.
ReplyDelete
ReplyDeleteGreat Article
Android Final Year Project Ideas for Computer Science
Project Centers in Chennai
Nice thanks for share, download latest VidMate
ReplyDeletethank you for this sharing
ReplyDeleteCheck out the best home office desks nz
GBWhatsapp is one of the best modded version of official Whatsapp with latest features.
ReplyDeleteGbwhatsapp
free version for pc https://dpcwatchdogviolation.info/
ReplyDeleteOutstanding post and Thank you for sharing such useful information with us. Keep blogging...
ReplyDeletePega Training in Chennai
Pega Course
Primavera Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Job Openings in Chennai
Excel Training in Chennai
Spark Training in Chennai
Power BI Training in Chennai
Pega Training in Anna Nagar
Great experience for me by reading this blog. Nice Article.
ReplyDeleteEthical Hacking course in Chennai
Ethical Hacking Training in Chennai
Hacking course
ccna course in Chennai
Salesforce Training in Chennai
Angular 7 Training in Chennai
Web Designing course in Chennai
Ethical Hacking course in Thiruvanmiyur
Ethical Hacking course in Porur
Ethical Hacking course in Adyar
ac market apk
ReplyDeleteoutsourcingall.com Most Poplar Free Porn Training Center largest The coolest Free Porn Videos & Sex Movies Updated Daily. Update is a tube porn site with millions Online and offline real life porn cam
ReplyDeleteNice thanks for share, download latest Snaptube Apk
ReplyDeleteNice thanks for share, download latest lucky patcher is one of the most popular android tool must check lucky patcher apk download
ReplyDeleteWe all know about the app GBWhatsApp which is the most popular among all mods of whatsapp. It is unofficial also but there is a lot of features in this app that made people crazy. Today with the new technology people want advance technology in modern era that’s why people attracted more with mods of apps then official. As we know that there are many mods of whatsapp available but GBWhatsApp is the best in all of these.for more Updates Visit Our GBWhatsApp APK
ReplyDeleteFree Random Live Video Streaming App Video chat: is ideal for one-to-one conversations that you can meet and match fun and interesting single all over the world in seconds.
ReplyDeleteThanks for sharing this valuable information with us..
ReplyDeleteEvent management company in chennai
Wedding Planners in chennai
wedding photographers in chennai
Thanks for sharing valuable information.
ReplyDeleteDigital Marketing training Course in chennai
digital marketing training institute in chennai
digital marketing training in Chennai
digital marketing course in Chennai
digital marketing course training in omr
digital marketing certification in omr
digital marketing course training in velachery
digital marketing training center in chennai
digital marketing courses with placement in chennai
digital marketing certification in chennai
digital marketing institute in Chennai
digital marketing certification course in Chennai
digital marketing course training in Chennai
Digital Marketing course in Chennai with placement
digital marketing courses in chennai
What a great article! I like your post, its quite informative. Extraordinary things you've generally imparted to us. Thanks for posting.
ReplyDeleteHSC Routine 2020
JSC Result 2019
PSC Results 2019
I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
ReplyDeleteCyber Security Projects for Final Year
JavaScript Training in Chennai
Project Centers in Chennai
JavaScript Training in Chennai
wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.
ReplyDeleteshowbox apk download