Saturday, 21 March 2020

Appium - webAutomation





<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.3</version>
</dependency>




package com.gitlab.appium;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class NewTest2 {

public static void main(String[] ards) throws MalformedURLException {

// Created object of DesiredCapabilities class.
DesiredCapabilities capabilities = new DesiredCapabilities();

// Set android deviceName desired capability. Set your device name.
capabilities.setCapability("deviceName", "J7AXPW");

capabilities.setCapability("udid", "J7AXPW");

// Set BROWSER_NAME desired capability. It's Android in our case here.
capabilities.setCapability("browserName", "Chrome");

// Set android VERSION desired capability. Set your mobile device's OS
// version.
capabilities.setCapability("platformVersion", "9.0");

// Set android platformName desired capability. It's Android in our case
// here.
capabilities.setCapability("platformName", "Android");

capabilities.setCapability("noReset", true);

// Set ChromeDriver location
System.setProperty("webdriver.chrome.driver", "C:\\Users\\KKasthuri\\Downloads\\chromedriver_win32\\chromedriver.exe");
AppiumDriver<MobileElement> driver = null;
try {
driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}

// Open URL in Chrome Browser
driver.get("http://www.google.com");
driver.quit();
}
}

Friday, 6 March 2020

Program - Given an array A[] and a number x, check for pair in A[] with sum as x

hasArrayTwoCandidates (A[], ar_size, sum)
1) Sort the array in non-decreasing order.
2) Initialize two index variables to find the candidate 
   elements in the sorted array.
       (a) Initialize first to the leftmost index: l = 0
       (b) Initialize second  the rightmost index:  r = ar_size-1
3) Loop while l < r.
       (a) If (A[l] + A[r] == sum)  then return 1
       (b) Else if( A[l] + A[r] <  sum )  then l++
       (c) Else r--    
4) No candidates in whole array - return 0
// Java program to check if given array 
// has 2 elements whose sum is equal 
// to the given value 
import java.util.*; 

class GFG { 
 // Function to check if array has 2 elements 
 // whose sum is equal to the given value 
 static boolean hasArrayTwoCandidates(int A[], 
          int arr_size, int sum) 
 { 
  int l, r; 

  /* Sort the elements */
  Arrays.sort(A); 

  /* Now look for the two candidates 
  in the sorted array*/
  l = 0; 
  r = arr_size - 1; 
  while (l < r) { 
   if (A[l] + A[r] == sum) 
    return true; 
   else if (A[l] + A[r] < sum) 
    l++; 
   else // A[i] + A[j] > sum 
    r--; 
  } 
  return false; 
 } 

 // Driver code 
 public static void main(String args[]) 
 { 
  int A[] = { 1, 4, 45, 6, 10, -8 }; 
  int n = 16; 
  int arr_size = A.length; 

  // Function calling 
  if (hasArrayTwoCandidates(A, arr_size, n)) 
   System.out.println("Array has two "
       + "elements with given sum"); 
  else
   System.out.println("Array doesn't have "
       + "two elements with given sum"); 
 } 
} 

Tuesday, 3 March 2020

Why WebDriver driver = new ChromeDriver() ?


Below is WebDriver Interface & Respective class implementation architecture.





ChromeDriver driver = new ChromeDriver(); // Lot of methods from parent calss RemoteWebDriver

vs

WebDriver driver = new ChromeDriver(); // we can access only few methods from WebDriver Interface & SerchContext Interface







Ex: Advantage of interface

Public List getList(){
       return new ArrayList<String>()
}

We can return any implemented class for any method which has return type as interface