Encode Password using Base64 Java - Selenium Webdriver



One of the most common practice while automating websites which have passwords and other personal information  is encoding.

Base64 is a method of encoding every 3 bytes of input into 4 bytes of output; it is commonly used to encode photos or audio to send in emails, and a way to hide webpage authentication from casual snooping. Here is an example of how to code a Base64 encoder in Java for Selenium WebDriver:

 import.org.apche.commons.codec.binary.Base64

WebDriver wd = new FirefoxDriver();
WebElement pwd = wd.findElement(By.id("passwd"));

byte[] encodedBytes = Base64.encodeBase64("TextforEncoding".getBytes());
System.out.println("encodedBytes " + new String(encodedBytes));
byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
System.out.println("decodedBytes " + new String(decodedBytes));

Happy Encoding!

Comments

Post a Comment

Popular posts from this blog

XPATH for IE / internet explorer

All time good software testing books!