Skip to main content

Posts

Selenium: Full Screen Vs Maximize

Full Screen Vs Maximize:: Do you know that in a Selenium we have a fullscreen() method that is different from maximize()? When maximized (driver.manage().window().maximize()), the title bar etc. of the window is still displayed. In fullscreen mode (driver.manage().window().fullscreen()), the title bar is not displayed. Until Selenium 3.x, there were several bug reported that fullscreen() feature doesn’t work mostly (not always) when using ChromeDriver and it throws org.openqa.selenium.UnsupportedCommandException: unknown command. We have a workaround to use ChromeOptions options.addArguments("start-fullscreen") in that case where you get "org.openqa.selenium.UnsupportedCommandException: unknown command" error on using fullscreen(). But in Selenium 4 (alpha 3), fullscreen() works like charm without any issue. hashtag # seleniumautomation hashtag # automationtesting hashtag # Selenium4

Selenium 4 - Switch to a new window or a new tab

If you have a use case where after navigating to a site you need to open another tab or a window and then navigate to some site on the new tab/window to perform some action there- then you can use these commands from Selenium 4: driver.switchTo().newWindow(WindowType.TAB); driver.switchTo().newWindow(WindowType.WINDOW); Tried and tested- works fine. hashtag # seleniumautomation hashtag # selenium4 hashtag # automationtesting

Screenshot of a specific element:: Selenium 3.x Vs Selenium 4

getScreenshotAs for WebElement was not supported until Selenium 3.x, so we had to take a long route like taking a complete viewable area screenshot and then cropping the part where we have our element by using getLocation, getSize, getWidth, getHeight and then finally getSubimage method like shown in image 1. But from Selenium 4 (at least alpha 3) onwards, getScreenshotAs is also supported for WebElement like this: public static void eleScreenshot() throws InterruptedException, IOException { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(" https://in.linkedin.com/ "); if(driver instanceof ChromeDriver) { File src = driver.findElement(By.xpath("/html/body/nav/a[1]/li-icon")).getScreenshotAs(OutputType.FILE); FileHandler.copy(src, new File("D:\\Learning_Automation\\Practise\\Image1.png")); } } Note* I u...

SeleniumBase (Selenium Python)

Most of us know that using WebDriverManager, we can automatically download the driver’s binary files (.exe files) for Web Automation in Selenium Java. But did you know that using SeleniumBase 1.32.10 which is for python we can achieve the same thing? i.e. If you don’t already have chromedriver or geckodriver(Firefox driver) downloaded for your browser tests to use, they will be downloaded automatically when you run your tests for the first time using the specified browser. hashtag # seleniumautomation hashtag # python hashtag # seleniumBase hashtag # tipsandtricks hashtag # drivers P.S. SeleniumBase is much more than WebDriverManager. SeleniumBase is a test framework that wraps Selenium and extends Pytest.

HTML Publisher Plugin not processing CSS for online Extent Report, Gatling, OWASP, etc. in Jenkins?

Reason:  It is because of the 'Content-Security-Policy' which is introduced in Jenkins from Jenkins 1.641 / Jenkins 1.625.3, which is blocking the inline CSS.  Read here for more details: https://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy Simplest solution:  Relaxing The Rules: Either use 'java -Dhudson.model.DirectoryBrowserSupport.CSP="" -jar jenkins.war' command to start Jenkins server from the command prompt or set this system property temporarily via the Jenkins Script Console: System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox; default-src 'self';") #jenkins   #reporting   #extent   #tips   #automationtesting    #testing   #seleniumautomation  

Automation Test Data

In automation space, who doesn't need random test data for things like let's say a name, address, CC, date, phone, etc.? We are always inclined to use a Java class that provides some random numbers or strings like this jk4h5j6hjkh for a name, address, city, etc. But isn't it dreadful? Do you guys know that there is a Faker library that is excellent at generating realistic test data? And that too based on your locale: https://github.com/DiUS/java-faker Do check this out too for the examples: https://java-faker.herokuapp.com/ I find it very shway. Do comment if you are already using it or like it. #seleniumautomation   #easierway   #betterway   #apiautomation   #testData   #automationtesting  

Need extension while running your SE scripts?

Though I am not able to find a good use case when we'll need an extension while running our automation Se scripts but in case, you need an extension while running your SE scripts, here's how you can do it: Step 1) Download Your Chrome Extension. To do this, get your webstore URL from the Google Web Store like " https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en "  Step 2) Then go to http://crxextractor.com/ and enter the Chrome web store URL that you get from Step 1 in the URL field to download the .crx file of the required extension. Step 3) Once you have the .crx file of that extension, it's time to save it somewhere so that you can use it in your SE script. Step 4) Use addExtensions method of ChromeOptions class in your SE script. Sample code: public class WithExt {   static WebDriver driver;  @Test  public static void chromeWithExtensions() throws InterruptedException { ...