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();
}
  }
}

11 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

Amazon Deals