/** * This method takes screen shot of web page. After taking screen shot, it saves that to file with * test method name and time stamp. This also writes a comment (having link to screenshot) to * selenium logging file created through LoggingSelenium. */ public void captureScreenShot(LoggingSelenium selenium, String screenshotsResultsPath) { try { final String SCREENSHOT_PATH = "screenshots"; /* String screenshotsResultsPath = new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath(); if (!new File(screenshotsResultsPath).exists()) { new File(screenshotsResultsPath).mkdirs(); }*/ String imageName = "Image" + timeStampForFileName() + ".png"; String finalImage = screenshotsResultsPath + File.separator + imageName; String browser = ConfigFileReader.getConfigItemValue("browser"); if (browser.equals("*chrome") || browser.equals("*firefox") || browser.equals("*iehta")) { // call captureEntirePageScreenshotToString method and it will // return Base64 encoded string referring to screen shot String base64Screenshot = selenium.captureEntirePageScreenshotToString(""); // Decode that Base64 encoded string to get actual screen shot. // Finally this screen shot will be written to file object. byte[] decodedScreenshot = Base64.decode(base64Screenshot); // create instance of FileOutputStream by passing it filename FileOutputStream fos = new FileOutputStream(new File(finalImage)); // Write decoded screenshot to fileoutputstream object fos.write(decodedScreenshot); fos.close(); } else { selenium.captureScreenshot(finalImage); } String failedSS = "<a href=\"file://" + finalImage + "\">Screenshot for previous action " + "</a>"; logger.debug(finalImage); // selenium.logComment(failedSS); selenium.logComment( "<a href=\"" + SCREENSHOT_PATH + "/" + imageName + "\"><img src=\"" + SCREENSHOT_PATH + "/" + imageName + "\" alt=\"Page Screen Shot\" width=\"150\" height=\"300\" border=\"5\"/></a>"); } catch (Exception e) { e.printStackTrace(); } }
public void readLogIn() { try { FileReader fr = new FileReader("log.tmp"); BufferedReader br = new BufferedReader(fr); String str; try { while ((str = br.readLine()) != null) { System.out.println(new String(Base64.decode(str))); } } catch (IOException ex) { Logger.getLogger(LogIn.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(LogIn.class.getName()).log(Level.SEVERE, null, ex); } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { EmailUtil as = new EmailUtil(); String host = "smtp.163.com"; String from = "*****@*****.**"; String username = "******"; String password = new String(Base64.decode("MTM0ODM3MjQwNTE=")); // 接收者邮箱 String to = "*****@*****.**"; String subject = "找回密码"; String mailConent = "找回密码"; // 调用发送附件邮件方法 as.sendAttachmentMail(host, from, username, password, to, subject, mailConent); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static byte[] decode(final String base64) { return Base64.decode(base64); }