Skip to main content

Posts

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 {

Wildcard in assertions error messages

Assume that you want to compare whether 2 numbers are equal or not. Most of us would do it like: @Test public void testCompare() { int x = 92; int y = 99; Assert.assertTrue("x is not equal to y", x == y); } And as we can see that these numbers aren't equal, so we'll get the error in this case. But it is not clear at all why the assertion fails as the values of x and y are not included in the failure message. FAILED: testCompare AssertionError: x is not equal to y Is there a way we can improve the message so that we can get the complete info from the error message itself? Yes, how about using wildcards in the error message: @Test public void testCompare() { int x = 92; int y = 99; String notEqualMsg = "%d is not equal to %d"; Assert.assertTrue(String.format(notEqualMsg, x, y), x == y); } FAILED: testCompare AssertionError: 92 is not equal to 99 Tada...problem solved!!! hashtag # easier hashtag # betterway hashtag # sele

Have you heard of "ngrok"?

It's a very cool tool that lets you expose a local webserver to the outside world (internet)- in short, it creates a secure tunnel on your local machine along with a public URL that you can use or give to your colleagues, friends, etc. for browsing or testing your local site. Go through this to know more about it: https://ngrok.com/docs I have used this where I wanted to expose my local running Jenkins to git for the webhook part.

Have you ever encountered this type of Exception where it says Element can't be clickable?

Element can't be clickable exception in Selenium : org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (660, 823) (Session info: chrome=76.0.3809.132) (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=XXX.XXXXX) Command duration or timeout: 65 milliseconds Most of the time. we go and first check manually to see that the element is visible and clickable. And then, you check the locator that you have selected is correct and the element also shows in the browser DOM. Then why is it failing? One of the reasons may be that the element is not in the viewport. So, how we can resolve this? Scroll to the page so that the element becomes visible, then hopefully the exception should not occur. JavascriptExecutor jsExec = (JavascriptExecutor)driver; jsExec.executeScript("window.scrollTo(0, document.body.scrollHeight)"); or WebElement element = document.getElementById("submit"); Javascript