Showing posts with label TestAutomation. Show all posts
Showing posts with label TestAutomation. Show all posts

Friday, 18 February 2022

How to setup Selenium Grid using Docker Desktop - Windows

                            Selenium Grid has made the test automation execution much faster and smarter. The excessive usage of selenium grid has its own hitches like too much of system resource utilization, all browsers to be installed on the system etc. 

With the introduction of docker images for selenium, made the life of testers lot easier. Out of multiple ways to bring up selenium grid with docker, I would choose the simple & quick way to bring up using docker-compose.

Pre-requisite: Docker desktop for windows is installed.


Steps to bring up Selenium Grid:

  • Pull required version of selenium hub and nodes using the command "docker pull" as below

         docker pull selenium/node-chrome-debug:3.141.59 

  • Create a yaml file with the below docker-compose instructions.
docker-compose file

  • run the command 
         docker-compose -f docker-compose.yml up -d

Friday, 4 June 2021

How to establish a connection to Remote Host & Copy file

Many times we do get the requirement, to connect a remote server & perform operations like copying a file from local to remote, vice versa and many others. But, have you ever thought how do we do that through java.? Yes, We can. Java has multiple libraries which can perform this task. One such java library which can perform this task is Jcraft's 'JSch (Java Secure Channel)' . 

Below example will let you know how to connect a remote host & perform copy operations.


public void copyFiletoRemotehost(String username,String pwd,String[] remotehosts, String port) {
        Session jschSession = null;
        int SESSION_TIMEOUT = 10000;
        final int CHANNEL_TIMEOUT = 5000;
        String REMOTE_HOST = "";
        int REMOTE_PORT = 22;
		
	String lFile = "C:/localhost/local.txt";
        String rFile = "/localtoRemote.txt";
        try {
            JSch jsch = new JSch();
            for(int i=0; i < remotehosts.length; i++) {
            	REMOTE_HOST = remotehosts[i].toString();
            	jschSession = jsch.getSession(username, REMOTE_HOST, REMOTE_PORT);

                //Remove known_hosts requirement
                java.util.Properties config = new java.util.Properties();
                config.put("StrictHostKeyChecking", "no");
                jschSession.setConfig(config);
                
                //authenticate using password
                jschSession.setPassword(pwd);
                jschSession.connect(SESSION_TIMEOUT);
                Channel sftp = jschSession.openChannel("sftp");
                sftp.connect(CHANNEL_TIMEOUT);

                ChannelSftp channelSftp = (ChannelSftp) sftp;
                channelSftp.put(lFile, rFile);
                channelSftp.exit();
                
                //Copy from one location to another with remote server
                copyFile(jschSession);
                jschSession.disconnect();
            }
        } catch (JSchException | SftpException e) {
            e.printStackTrace();
        } finally {
            if (jschSession != null) {
                jschSession.disconnect();
            }
        }
    }
    
    /**
    * This method will let you copy from one folder to another within the remote server
    */
    public static void copyFile(Session jschSession) throws JSchException {
	String cmd1 = "cp C:/username/localtoRemote.txt  C:/anotherfolder/localtoRemote.txt";
	Channel exec = jschSession.openChannel("exec");
		
	ChannelExec channelExec = (ChannelExec) exec;
	channelExec.setCommand(cmd1);
	exec.connect(CHANNEL_TIMEOUT);
	channelExec.setErrStream(System.err);
   }

References:
http://www.jcraft.com/jsch/

Monday, 29 August 2016

How to read QR Code or Barcode from Images

Reading Barcodes / QR codes from images seems to be difficult & using the below open source libraries(ZXing - Zebra Crossing) provided by Google will make it simple for any application to include this functionality.

Curious on knowing how Android Apps scan the Barcodes or QR codes from the camera?

The android apps designed to scan 1D & 2D barcodes on a high level convert the data the camera into image bytes to the below library, which in-turn return the data embedded within the bar codes.

Follow the below steps to achieve the same.