Wednesday, December 24, 2014

Flipkart (Native App) Automation Script - Using Selendroid For Android

Script I :

package Flipkart_Complete_Partap;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import io.selendroid.device.DeviceTargetPlatform;

import org.openqa.selenium.WebDriver;

@Test
public class Test_Case
{
String username;
String password;
String SearchProduct;
String objCommon;
Common_Methods _objCommon = new Common_Methods();
private static SelendroidLauncher selendroidServer = null;
private static WebDriver _driver = null;

@BeforeClass
public void setUp() throws FileNotFoundException, IOException
{
Properties prop = new Properties();
prop.load(new FileInputStream("PropFile_Flipkart_Ankit.prop"));
username = prop.getProperty("UserName");
System.out.println(username);
password = prop.getProperty("Password");
System.out.println(password);
}

@Test
public void test() throws InterruptedException
{
_objCommon.login(_driver, username, password);
_objCommon.captureScreenshot(_driver);
_driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
_objCommon.Search_Product(_driver);
_objCommon.captureScreenshot(_driver);
_objCommon.addtocart(_driver);
_objCommon.captureScreenshot(_driver);
_objCommon.add_address(_driver);
_objCommon.captureScreenshot(_driver);
}

@BeforeClass
public static void startSelendroidServer() throws Exception
{
if (selendroidServer != null)
{
selendroidServer.stopSelendroid();
}
SelendroidConfiguration config = new SelendroidConfiguration();
config.addSupportedApp("com.flipkart.android:2.5.2");
selendroidServer = new SelendroidLauncher(config);
selendroidServer.launchSelendroid();
SelendroidCapabilities caps = new SelendroidCapabilities("com.flipkart.android:2.5.2");
/*caps.setPlatformVersion(DeviceTargetPlatform.ANDROID17);
caps.setSerial("QO4417C05204")*/;
_driver = new SelendroidDriver(caps);
}

@AfterClass
public static void stopSelendroidServer() throws InterruptedException
{
if (_driver != null)
{
Thread.sleep(30000);
_driver.quit();
}
if (selendroidServer != null)
{
selendroidServer.stopSelendroid();
}
  }
}

---------------------------------------------------------------------------------------------------------------------

Library Class
-----------------------------------------------------------------------------------------------------------------------

package Flipkart_Complete_Partap;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import io.selendroid.device.DeviceTargetPlatform;

import org.openqa.selenium.WebDriver;

@Test
public class Test_Case 
{
String username;
String password;
String SearchProduct;
String objCommon;
Common_Methods _objCommon = new Common_Methods();
private static SelendroidLauncher selendroidServer = null;
private static WebDriver _driver = null;

@BeforeClass
public void setUp() throws FileNotFoundException, IOException 
{
Properties prop = new Properties();
prop.load(new FileInputStream("PropFile_Flipkart_Ankit.prop"));
username = prop.getProperty("UserName");
System.out.println(username);
password = prop.getProperty("Password");
System.out.println(password);
}

@Test
public void test() throws InterruptedException 
{
_objCommon.login(_driver, username, password);
_objCommon.captureScreenshot(_driver);
_driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
_objCommon.Search_Product(_driver);
_objCommon.captureScreenshot(_driver);
_objCommon.addtocart(_driver);
_objCommon.captureScreenshot(_driver);
_objCommon.add_address(_driver);
_objCommon.captureScreenshot(_driver);
}

@BeforeClass
public static void startSelendroidServer() throws Exception 
{
if (selendroidServer != null) 
{
selendroidServer.stopSelendroid();
}
SelendroidConfiguration config = new SelendroidConfiguration();
config.addSupportedApp("com.flipkart.android:2.5.2");
selendroidServer = new SelendroidLauncher(config);
selendroidServer.launchSelendroid();
SelendroidCapabilities caps = new SelendroidCapabilities("com.flipkart.android:2.5.2");
/*caps.setPlatformVersion(DeviceTargetPlatform.ANDROID17);
caps.setSerial("QO4417C05204")*/;
_driver = new SelendroidDriver(caps);
}

@AfterClass
public static void stopSelendroidServer() throws InterruptedException 
{
if (_driver != null) 
{
Thread.sleep(30000);
_driver.quit();
}
if (selendroidServer != null)
{
selendroidServer.stopSelendroid();
}
  }
}

14 comments:

  1. Thanks for giving important information to training seekers,Keep posting useful information,Click below to find.

    Mobile Application Development and Testing Training

    ReplyDelete
  2. Hello
    The Article on Native App Automation Script,Using Selendroid For Android is nice ,give detail information about it .Thanks for sharing the information about it.
    Xamarin Consulting

    ReplyDelete
  3. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...

    Mobile App Development Company
    Mobile App Development Company
    Mobile app Development Companies

    ReplyDelete

  4. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..
    please sharing like this information......
    Android training in chennai
    Ios training in chennai

    ReplyDelete

  5. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Android App Development Company

    ReplyDelete
  6. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    iOS App Development Company
    iOS App Development Company

    ReplyDelete
  7. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    <Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text
    Mobile Marketing Services
    mobile marketing companies
    Sms API

    ReplyDelete
  8. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete
  9. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Mobile Marketing Service
    Mobile Marketing Companies

    ReplyDelete
  10. Nice post.Thanks for sharing
    Indian Cyber Army’s most awaited internship is live now. Summer Internship 2018 on “ Ethical hacking” and book your seats before it runs out.Candidates have to get themselves registered to be a part of this Internship program. Here internship will give you on-the-job experience, help you learn whether you and Cyber security industry are a good match and can provide you with valuable connections and references. Here interns are usually exposed to a wide variety of tasks and responsibilities which allows the intern to showcase their strengths by working on projects for various managers that work on different parts of Indian Cyber Army. Becoming a high performing intern is a fantastic way to improve your employment prospects. This internship can be a great way to get your foot in the door of success with a prestigious or desirable Organization.As career in ethical hacking is most in demand.

    ReplyDelete
  11. Thanks for the information.It is really nice .Information security is the set of processes that maintain the confidentiality, integrity and availability of business data in its various forms.In this age of Technology advancement, computer and information technology have not only brought convenience to citizens in modern life but also for policemen & various Government officials of the nation to fight cybercrime through various modus operandi. Indian Cyber Army has been dedicated in fighting cyber crime, striving to maintain law and order in cyberspace so as to ensure that everyone remains digitally safe.Read more:- Information Security

    ReplyDelete
  12. thanks for sharing the more valuable information.
    Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses. The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.Ethical hacking training ,
    Ethical hacking course

    ReplyDelete