Posts

An unknown server-side error occurred while processing the command

If you encountered following error while executing appium test on android chrome An unknown server-side error occurred while processing the command. Original error: Failed to start Chroedriver session: A new session could not be created. (Original error: session not created exception: Chrome version must be >= 60.0.3112.0, use the option in below link https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md

How to upload image using sikuli

Though webdriver handles the file uploading smartly but there are some time when you need to work with external tools such as AutoIT, again AutoIT doesn't go good with linux system hence we may use sikuli to upload the image. Click on link which will populate the file upload dialog, and take printscreen for Fileupload area and open button and save them in some location. Pattern fileLoad = new Pattern("{yourPath}/FileLoadInput.png"); Pattern openButton = new Pattern("{yourPath}/openButton.png"); Screen src = new Screen(); src.setAutoWaitTimeout(30); // Clear the input field if any is selected by default. src.type("a", Key.CTRL); src.type(Key.BACKSPACE); //Type in input filed name of the image and click on open button src.type(fileLoad, sFileName); src.click(openButton);

Comparing sum of string's digit by splitting string in 2 halfs

import java.util.Scanner; public class Lottry { static boolean bLot = false; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String sNum = sc.next(); if(blottry(sNum)){ System.out.println("Won the lottry"); }else{ System.out.println("Not won the lottry"); } sc.close(); } static boolean blottry(String s){ int sum1 = 0; int sum2 = 0; char[]cLot = s.toCharArray(); System.out.println("Lenght of String digit::"+ cLot.length); if(cLot.length>=4 && cLot.length%2==0){ for(int i = 0; i<cLot.length/2; i++){ sum1 = sum1 + Character.getNumericValue(cLot[i]); } System.out.println("Sum1:::::::::::::::"+ sum1); for(int i=cLot.length-1; i >= cLot.length/2; i--){ sum2 = sum2 + Character.getNumericValue(cLot[i]); } System.out.println("Sum2:::::::::::::::"+ sum2); } if(sum1==sum2){ ...

Parsing xml node tags using documentbuilderfactory

package test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class xmlTest { public static void main(String[] args) throws Exception { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse("filePath"); NodeList nlist = doc.getElementsByTagName("param"); System.out.println(nlist.getLength()); for(int ent=0; ent<nlist.getLength(); ent++){ System.out.println(doc.getElementsByTagName("param").item(ent).getTextContent()); } } }

Folders in any given directory

import java.io.File; import java.util.ArrayList; import java.util.List; public class FilesinDir { public static void main(String[] args) { File f = new File("C:\\path"); File[] fl = f.listFiles(); boolean flag = false; List<String>folder = new ArrayList<String>(); for(File f2: fl) { String s = f2.getName(); for(int i = 0; i<s.length(); i++) { if(s.charAt(i)=='.') { flag = false; }else { flag = true; } } if (flag==true){ folder.add(s); } } System.out.println("total number of folders are::"+folder.size()); System.out.println("folders in dir are::"+ folder); } }

Convert decimal to binary and then convert to inverse of binary by changing 0 to 1 and 1 to 0

public class test { public static void main(String[] args) { System.out.println(getIntegerComplement(50)); } static int getIntegerComplement(int n) { String binary = ""; String rev =""; StringBuilder sb = new StringBuilder(); int k; while(n>0){ int r= n%2; binary = r+binary; n= n/2;         } System.out.println("binary for n is::"+ binary); for(int i=0; i<binary.length(); i++) { sb.append(binary.charAt(i)); if(sb.charAt(i)=='0') { sb.replace(i, i+1, "1"); }else{ sb.replace(i, i+1, "0");         } } rev = sb.toString(); k = Integer.parseInt(rev); int decimal=0; int power=0; int l=k; while(l>0) { int tmp = l%10; decimal = (int) (decimal+ tmp*Math.pow(2, power)); l=l/10; power++; } System.out.println("decimal of inverse is:::"+ decimal); System.out.print("inverse binary of n is:::")...

How to generate string with given range.

Say there is drop down list to select range e.g. 1-9 and based on that range you need to input value in text field having length equal to range. public class testlength { public static String test(int idgit) { String s = null; Random m = new Random();       // take a temp string and initialize it randomly or hardcoded it String temp = "5" //Integer.toString(m.nextInt(8)); for(int i=1; i<idgit+k;i++) { int j= m.nextInt(8);     s = Integer.toString(j);     temp = temp+s; } return temp; }