Wednesday 29 March 2017

Change Different Network Speed in IPhone(3G to 2G)

How to Change network Speed in Iphone.

Requirement ::

1. Mac OS
2. Iphone (Any version)
3. Iphone Cable
4. Wifi or Mobile Data

Steps to Change network::

Step1 ::
     
           Connect Cable to Mac Os & Iphone

Step 2 ::
   
           Go to Settings

Step 3 ::

       Scroll Down to Developer Option. & Select Developer Tab.


Step 4 ::

            Now Click on Status Tab.



Step 5 ::

          Now Select Which network u require to operate Network.



Continue with using Speed based network..



By 

Harikrishna Recharla


      

Friday 24 March 2017

Create New Simulator in XCODE

Setup for Creating New Simulator in Xcode.

Requirement ::

1.MAC os
2.Xcode


Install xcode from AppStore

Signin With your Apple ID

Step 1::

Open Xcode.

Click on Create a new Xcode Project


STEP 2 ::


STEP 3 ::



STEP 4 ::

Select folder And Click on Create.

STEP 5 ::

 U will get below screen.

STEP 6 ::

Click on play Button 

You Will see Simulator.




All The Best

Launch Application with Different Browsers

Launching Browser With Different Ways with FIREFOX, CHROME, IE, SAFARI, OPERA





public WebDriver Launch()
{
String browser = getpropvalue("Browser");
if (browser.equalsIgnoreCase("ff")) 
{
wdriver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("chrome")) 
{
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", getpropvalue("chromepath"));
wdriver = new ChromeDriver(options);
wdriver.manage().window().maximize();
navigateToURL();
}
else if (browser.equalsIgnoreCase("ie")) 
{
System.setProperty("webdriver.ie.driver", "./drivers/IEDriverServer_x32_v2.47.0.exe");
wdriver = new InternetExplorerDriver();
}
else if (browser.equalsIgnoreCase("safari")) 
{
wdriver = new SafariDriver();
}
else if (browser.equalsIgnoreCase("opera")) 
{
wdriver = new OperaDriver();
}
launchBrowser();
return wdriver;

}

Thursday 23 March 2017

Asserting value using testNg

Assert using TestNG

Compare Two Different Strings values




public void assertvalue(String actual,String expected)
{
Assert.assertEquals(actual, expected);
Reporter.log("Expected ::"+actual+"  Expected::"+expected, true);

}

Read Config.Proprties file

How to Read Config.properties File with Key & Value Pair




public String readPropertyOf(String key){

String propValue = null;
try {
FileInputStream input = new FileInputStream("./config.properties");
Properties prop = new Properties();
prop.load(input);
propValue = prop.getProperty(key);
} catch (IOException e) {
System.out.println("Caught the below exception!");
e.printStackTrace();
}
return propValue;

}




public static void main(String[] args)
{
   String readname =   readPropertyOf("name");
    System.out.println(readname);

  }

Scroll Web Application in Selenium Webdriver

Scroll Application UP & DOWN Until Element Visible

Scroll UP ::


public  void scrollup(String xValue
{    
String parameter="scroll(" +xValue+ ",0)"
JavascriptExecutor jse = (JavascriptExecutor)wdriver;
jse.executeScript(parameter); //xvalue '500' can be altered

}


Scroll Down ::

public  void scrolldown(String num) {
JavascriptExecutor jse = (JavascriptExecutor) wdriver;
    jse.executeScript("window.scrollBy(0,"+num+")", "");
}



Scroll Until Element Visible ::


public  void scrollToElementViaJavascript(WebElement element
{        
((JavascriptExecutor) wdriver).executeScript("arguments[0].scrollIntoView();", element);     
}



Monday 20 February 2017

Exceptions In Selenium

Exceptions we get in Selenium::

No such element
Null pointer
Unreachable browser exception
class not found in classpath
timeoutexception
not visible exception
element not selectable exception
Stale element exception
no alert exception
invalid exception
WebDriver Exception

Monday 13 February 2017

Read Cell value From Excel.xlsx (Generic)

Reading Excel cell value::

Below code is taken based Database Reading.


public String  readData(String sheetname,String row,String column
{
try{
FileInputStream fis=new FileInputStream("./TestData.xlsx");
Workbook wb=WorkbookFactory.create(fis);
        Sheet sh=wb.getSheet(sheetname);
int noofrows=sh.getLastRowNum()+1;
int noofcolumns=sh.getRow(1).getLastCellNum();
for(int i=0;i<noofrows;i++)
          {
String r=sh.getRow(i).getCell(0).toString();
if(r.equals(row))
{
for(int j=0;j<noofcolumns;j++)
         {
String c=sh.getRow(0).getCell(j).toString();
if(c.equals(column)){
try{
double value=sh.getRow(i).getCell(j).getNumericCellValue();
        String data=BigDecimal.valueOf(value).toPlainString();
return data;
}catch(Exception e){
        String data1=sh.getRow(i).getCell(j).getStringCellValue();
return data1;
}}}}}
return column;
}catch(Exception e){}
return column;

}

Launch IOS Application using Appium(Selenium)


Code for Launching IOS application::

Below code will help u to launch IPA in Real Device.

Find another blog for setting up Xcode operations.


public AppiumDriver Launch_IOSApp()
{
File file = new File(s);
//Launching IOS App
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "9.3");
capabilities.setCapability("deviceOrientation", "portrait");
capabilities.setCapability("browserName", "");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("deviceName", "iphone");
capabilities.setCapability("udid", "fabad62540cc0088bfc9f2af5c154985420a856e");
capabilities.setCapability("xcodeConfigFile", "/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");
capabilities.setCapability("appPath",file.getAbsolutePath());
capabilities.setCapability("realDeviceLogger","/usr/local/lib/node_modules/deviceconsole");
capabilities.setCapability("bundleId","com.proj.ios");
try {
idriver = new IOSDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return idriver;

}

Enable & Disable WIFI in Android

Enabling WIFI ::



public void enablewifi() throws InterruptedException{
NetworkConnectionSetting connection_wifi_on = new NetworkConnectionSetting(false, true, false);
Thread.sleep(10000);
Reporter.log("Enabled WIFI connection");

}




Disable WIFI ::

public  void disbalewifi() throws InterruptedException, MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), capabilities);

// init wi-fi and data enabled and airplane mode disabled
NetworkConnectionSetting ncs = new NetworkConnectionSetting(false, true, true);
driver.setNetworkConnection(ncs);
// turn off wi-fi
ncs.setWifi(false);
driver.setNetworkConnection(ncs);
NetworkConnectionSetting conn = new NetworkConnectionSetting(false, false, false);
conn.setWifi(false);
Thread.sleep(10000);
Reporter.log("Disabled WIFI connection");
}

Appium Start & Stop via CMD(Using SeleniumJava)

Start Appium using CMD::


public void startAppium() throws IOException, InterruptedException { 
Reporter.log("Starting Appium Server ", true);
String AppiumNodeFilePath = getPropertyOf("AppiumNodeFilePath");
        String AppiumJavaScriptServerFile = getPropertyOf("AppiumJavaScriptServerFile");
        String AppiumServerAddress = getPropertyOf("AppiumServerAddress");
        String AppiumServerPort = getPropertyOf("AppiumServerPort");
CommandLine command = new CommandLine("cmd"); 
command.addArgument("/c"); 
command.addArgument(AppiumNodeFilePath); 
command.addArgument(AppiumJavaScriptServerFile); 
command.addArgument("--address"); 
command.addArgument(AppiumServerAddress); 
command.addArgument("--port"); 
command.addArgument(AppiumServerPort); 
command.addArgument("--no-reset");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 
DefaultExecutor executor = new DefaultExecutor(); 
executor.setExitValue(1); 
executor.execute(command, resultHandler); 
AppiumServiceBuilder builder = new AppiumServiceBuilder();
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "info");
// Wait for 15 minutes so that appium server can start properly before going for test execution. // Increase this time If face any error. 
Thread.sleep(12000);

}



Stop Appium Server ::



public void stopAppium() throws IOException, InterruptedException { 
// Add different arguments In command line which requires to stop appium server. 
Reporter.log("Stopping Appium server", true);
Thread.sleep(2000);
CommandLine command = new CommandLine("cmd"); 
command.addArgument("/c"); 
command.addArgument("taskkill"); 
command.addArgument("/F"); 
command.addArgument("/IM"); 
command.addArgument("node.exe"); 
// Execute command line arguments to stop appium server. 
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 
DefaultExecutor executor = new DefaultExecutor(); 
executor.setExitValue(1); 
executor.execute(command, resultHandler);
}

Parallel Execution With Different Users .. using TestNG & DataProviders

Concurrent Execution with Different Browsers & Different Users.


BROWSER::

Set UP Browser to be Launched.

public WebDriver LaunchBrowser()
{
String browser = getpropvalue("Browser");
if (browser.equalsIgnoreCase("ff")) 
{
wdriver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("chrome")) 
{
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver",
getpropvalue("chromepath"));
wdriver = new ChromeDriver(options);
wdriver.manage().window().maximize();
}
else if (browser.equalsIgnoreCase("ie")) 
{
System.setProperty("webdriver.ie.driver", "./drivers/IEDriverServer_x32_v2.47.0.exe");
wdriver = new InternetExplorerDriver();
}
else if (browser.equalsIgnoreCase("safari")) 
{
wdriver = new SafariDriver();
}
else if (browser.equalsIgnoreCase("opera")) 
{
wdriver = new OperaDriver();
}
launchBrowser();
return wdriver;
} 


Naviagte URL::

public void navigateurl()
{
              wdriver.get("URL");
}

Login Setup::

public void enterCredentials_For_multiple(String email)
{

             wdriver.findElement(By.xpath("//Login")).click();
      wdriver.findElement(By.xpath("")).sendKeys(email);
wdriver.findElement(By.xpath("Password")).sendKeys("");

}

Data Providers ::

This will help to provide different set of Data.

1.First Approach

@DataProvider(parallel = true)
public Object[][] getdata() throws EncryptedDocumentException, InvalidFormatException, IOException
{
Object[][] data = {{"harikrishna@gmail.com"},{"test@gmail.com"},{"test2@gmail.com"}};
return data;
}

2.Second Approach ::

Read From Excel File with Passing Different Set of Data

public String getLoginData(String uName) throws IOException, InvalidFormatException
{
String pass = null;
FileInputStream fis=new FileInputStream("../testdata/securityTestData.xls");
Workbook wb=WorkbookFactory.create(fis);
Sheet sh=wb.getSheet("concurrentLogin");
int noOfRows=sh.getLastRowNum();
for(int i=1;i<=noOfRows;i++)
{
Row row=sh.getRow(i);
if(row.getCell(0).getStringCellValue()==uName)
pass=row.getCell(1).getStringCellValue();
}
return pass;
}



Now Set testNg.xml ::