Skip to main content

Posts

Showing posts with the label java

Solution for com.jcraft.jsch.JSchException: reject HostKey problem on Ubuntu

Just a random investigation with a workaround. So trying to connect to SFTP server using jsch library, but getting a nasty com.jcraft.jsch.JSchException: reject HostKey exception. This host is already present in ~/.ssh/known_hosts file, so it should not be problem, but it is. It turns out this problem happens if SFTP server is running on Ubuntu and strictHostKey is set to true, but it doesn't happen on Linux Fedora. I suppose this is because host entries in the known_hosts file on Ubuntu are encrypted in a different way than in known_hosts on Fedora, so it cannot be recognized or decrypted by JSch library. Now all you need to do is manually add host entries to the file. Basically you just get the public key for the host where SFTP server is running using this command: ssh-keyscan -t rsa sftp_server_ip_address_or_hostname Then copy-paste the output to your local ~/.ssh/known_hosts file. That's all, it should work now. If it doesn't, try to empty known_hosts file complet

Disabling browser "Save As" dialog in Selenium WebDriver tests

How to disable Save As dialog in Selenium WebDriver tests? Solution for Firefox (add more MIME media types if necessary): FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browser.download.folderList",2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false); firefoxProfile.setPreference("browser.download.dir", "/save/file/to/this/directory"); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/html, application/xhtml+xml, application/xml, application/csv, text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream"); WebDriver driver = new FirefoxDriver(firefoxProfile); Solution for Google Chrome (this applies to all MIME media types): Map prefs = new Hashtable<>(); prefs.put("download.prompt_for_download", "false"); prefs.put("download.

Using querySelector in Selenium WebDriver

Sometimes it's very helpful if we are able to click some element directly, by calling JavaScript click event. For example, this can be the case when the element is not visible, or not clickable, thus we cannot use native WebDriver methods. WebDriver driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.querySelector('.pane .object_options .dropdown-toggle span').click();");

Multiplatform Java solution to take a screenshot in your tests

This small chunk of code will help you to take a screenshot of entire screen on any platform. It is especially helpful in test automation frameworks to add "take a screenshot on failure" functionality. captureScreen method accepts the filename of the image to be produced in PNG format including the full path (absolute or relative to the working directory), e.g. "out/screenshots/myscreen.png"

JMeter handling dynamic ViewState parameter in Seam framework

Testing applications built with Seam Java framework is possible with JMeter like any other web applications, though there are some nuances to take into account. One of them is ViewState parameter. This parameter is dynamic and it means that we cannot just leave it hardcoded in our JMeter script because it will be broken the next time you try to execute it. Why this happens? Let's dig a little deeper. Black-box testing doesn't require us to know how Seam framework works, right? Okay, in this case we only need to know how it affects our tests. As testers we need to make sure that ViewState parameter in the POST request has the same value as returned by a previous GET request. For example you have two subsequent requests: GET http://x.x.x.x:8080/some_page.seam POST http://x.x.x.x:8080/some_page.seam The first request opens a page and the second one performs an action on the page (for instance - expands some tab, tree, etc). If you analyze the response data with a list