Java Code:
import org.apache.commons.codec.binary.Base64;
public class DecodeAndEncodePassword {
public static void main(String[] args) {
String str="test123";
// Encode data on your side using BASE64
byte[] encodedString = Base64.encodeBase64(str.getBytes());
System.out.println("encoded value is " + new String(encodedString));
// Decode data on other side, by processing encoded data
byte[] decodedString = Base64.decodeBase64(encodedString);
System.out.println("Decoded value is " + new String(decodedString));
}
}
Selenium Code
import static org.testng.Assert.assertNotEqualsDeep;
import org.apache.commons.codec.binary.Base64;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestCasewithEncryptedPassword {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C://Drivers//chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://demo.nopcommerce.com/");
driver.findElement(By.linkText("Log in")).click();
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys("pavanoltraining@gmail.com");
driver.findElement(By.xpath("//*[@id='Password']")).sendKeys(decodeString("dGVzdDEyMw=="));
driver.findElement(By.xpath("//input[@value='Log in']")).click();
}
static String decodeString(String password)
{
byte[] decodedString = Base64.decodeBase64(password);
return(new String(decodedString));
}
}