Skip to main content

Posts

Showing posts from October, 2019

Jenkins: set of commands to safely stop/restart it

Not sure about you guys but I used to stop/restart Jenkins using cmd prompt only but it looks like we have an optimized way to stop/restart i.e. through the Jenkins instance itself. Jenkins provides a set of commands to safely stop/restart Jenkins by putting it in a quiet mode. 1) quietDown: Put Jenkins in a Quiet mode, in preparation for a restart. In that mode, Jenkins doesn’t start any build 2) cancelQuietDown: Cancel the effect of the “quiet-down” command. 3) safeRestart: Put Jenkins into the quiet mode, wait for existing builds to be completed, and then restart Jenkins. 4) safeExit: Put Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins. Just hit these URLs on the browser where your jenkins is running by replacing "<jenkins.server>" with your Jenkins domain URL. http://<jenkins.server>/restart http://<jenkins.server>/safeRestart http://<jenkins.server>/exit http://<jenkins.server>/

Page Object Model- Selenium

A basic rule of Page Object Model: "If you have WebDriver APIs in your test methods, You're Doing It Wrong" - Simon Stewart A good read: https://www.pluralsight.com/guides/getting-started-with-page-object-pattern-for-your-selenium-tests hashtag # testautomation hashtag # seleniumautomation hashtag # automationtesting hashtag # pageobjectmodel

Selenium 4 Grid

Selenium 4 provides three kinds of Grid- Standalone, Traditional one (Hub, and Node), Fully Distributed (Process and Sessions) Give a shot to Standalone mode where by default, the server will detect available drivers that it can use (Chome, GeckoDriver, etc) by looking at the PATH. Make sure you place all the executable into your PATH. Here's the official link from Se where you can find all the details: https://github.com/SeleniumHQ/selenium/wiki/Selenium-Grid-4 hashtag # selenium4 hashtag # testautomation hashtag # automationtesting hashtag # seleniumgrid

Selenium- PageFactory not required @FindBy for ID and NAME

Did you know that if the element variable name is the same with the element id or element name, it's not mandatory to use FindBy annotation as these are known as Direct Locators? Like this: public class FindByExample { private WebDriver driver; @FindBy(id = "username") //here the text box has the locator id=username. private WebElement uname; @FindBy(name = "password") //here the text box has the locator name=password. private WebElement pwd; public FindByExample(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } The above code can be written with NO FindBy annotations if the web element variables have the same name or ID: public class FindByExample { private WebDriver driver; private WebElement username; private WebElement password; public FindByExample(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } hashta

Selenium 4: Chrome DevTools API

In Selenium 4, there is an Interface for Chrome DevTools API that lets you play with DevTools. Here is a list of few things that we can achieve by using DevTools API with Selenium: 1. Use Console capabilities 2. Emulate network conditions 3. Perform security operations 4. Get performance and Metrics of our Browser/Network The complete API can be found here: https://lnkd.in/f7ffwZq Showing below how we can listen to Chrome Console logs and close the browser using the "Devtools" interface. public static void chromeDevTools() throws InterruptedException, IOException { try { chromeDevTools = driver.getDevTools(); chromeDevTools.createSession(); message = "Hi everyone, this is Dheeraj."; driver.get(" https://lnkd.in/fM5JmnZ "); // execute Script to write console message driver.executeScript("console.log('" + message + "');"); } catch (Exception e) { e.printStackTrace(); } finally { // C

Disabling images - Selenium

One of the ways to increase the speed and performance of your Selenium test is to execute in the headless mode. Also, as we know that disabling images helps to speed up the page load times which make execution faster- so sometimes during run (though NOT recommended for regular test run OR in the case where you flow requires interaction with images like clicking on the button which is an image), if we are not bothered too much whether images are loading on the page and want our execution to be faster- we can disable the images. public static void disableChromeImages(ChromeOptions options) { HashMap images = new HashMap(); images.put("images", 2); // 0-default, 1-Allow, 2-Block HashMap prefs = new HashMap(); prefs.put("profile.default_content_setting_values", images); options.setExperimentalOption("prefs", prefs); } public static void disableFireFoxImages(FirefoxOptions options) { FirefoxProfile profile = new FirefoxProfile(); profi

Full page screenshot- Selenium 4 (Firefox for now)

Full page screenshot— Using Selenium 4 (alpha 2 or greater), now we can take the full page screenshots with getFullPageScreenshotAs() method in the Firefox. But instead of typecasting it to ‘TakesScreenshot’ interface, we need to typecast it to FirefoxDriver instance. File src = ((FirefoxDriver) driver).getFullPageScreenshotAs(OutputType.FILE); I checked but it looks like this method is not available for Chrome or any other browsers yet. hashtag # seleniumautomation hashtag # automationtesting hashtag # tipsandtricks hashtag # firefox hashtag # screenshot hashtag # selenium4