Posts

Custom annotations in Java

  Java Custom annotations  or Java User-defined annotations are easy to create and use. The  @interface  element is used to declare an annotation. Example: @interface  SampleAnnotation{}   Some key points: The method should not have any throws clauses The method should return one of the following: primitive data types, String, Class, enum or array of these data types. The method  should not have any parameters . We should attach @ just before the interface keyword to define annotation. It may assign a default value to the method. There are three types of annotations. 1.  Marker Annotation:   An annotation that has no method, is called marker annotation. For example: @interface  SampleAnnotation{}   The @Override and @Deprecated are marker annotations. 2.  Single-Value Annotation:   An annotation that has one method, is called a single-value annotation.  For example: @interface  SampleAnnotation{...

PYTHON Challenge

Image
 Problem: Write a python class and a method called getPositions to extract the positions of a given value. If no argument were provided, the default value is 0. clue: data = [1, 0, -1, 0, 0, 1, 1, 0, 0, -1]  item = MyClass(data)0 print(item.getPositions())  print(item.getPositions(1))  print(item.getPositions(-1)) Expected output: [1, 3, 4, 7, 8]  [0, 5, 6]  [2, 9] Solution: data=[1,0,-1,0,0,1,1,0,0,-1] class Myclass():     def __init__(self,data):         self.data=data     def getPositions(self,pos=0 ):         return [i for i,e in enumerate(data) if e==pos] item = Myclass(data) print(item.getPositions()) print(item.getPositions(1)) print(item.getPositions(-1))

Running tests from maven command line: Different options

Image
  When we work on developing automation scripts ,we may sometime need run based on different conditions. Let us see some here. Assuming Prerequisite met for running : Some TestClasses with TestMethods are present in Framework Maven is used as build tool for Framework design. Using TestNG framework for Test Cases The following are the steps: Run specific test from a test class: mvn -Dtest=Testclassname#testmethodname test To run all tests in class: mvn -Dtest=classname test To run test that match a pattern: This will run all tests that starts with  testcreate  in class named  Testclassname mvn -Dtest=Testclassname#testcreate* test Run all test methods match pattern ‘testFoo*’ and ‘testBar*’ from a test class: mvn test -Dtest=Test1#testFoo*+testBar* To run multiple methods in a testclass: mvn -Dtest=Testclassname#testone+testtwo test T o  run Multiple method from multiple class : mvn test -Dtest=CLASS_NAME1#METHOD_NAME1,CLASS_NAME2#METHOD_NAME2 To run multiple tes...

How to compare two images(logos) with selenium

Image
 

How would we make sure that a page is loaded using Selenium and WebDriver?

While automating the script, the tester has to take care that the page is loaded properly otherwise on performing some action execution will fail.  There are some ways defined below to make sure the page is loaded : 1. Using  loading spinner: While the page is loading there is a loading spinner on the web page, the tester can wait for the invisibility of that spinner (new WebDriverWait(webDriver, 120)).until(ExpectedConditions.invisibilityOfElementLocated(by)); 2. By using JavascriptExecutor :  It is an interface which provides a mechanism to execute JavaScript through selenium web driver ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete")

How to handle random pop ups

Issue:  In some pages unexpected popup's(ex:ad's) will be displaying. Because of this the script will fail by throwing exceptions like  ElementNotFoundException   and currently  Element is not Interactable  etc.. . Here these ad's are not specific to particular page. It may come at any page.   How to handle? A popup can be an alert or an ad in a iframe or an ad in a new window and all these are treated in different ways. Assuming its an Alert, log_file has already provided you the solution, i.e. to use  alertIsPresent () , and accept or dimiss it as per your requirements. Assuming the ad is in  iframe , follow the below approach: driver .switchTo .frame (driver.findElement(By.id(locatorToIdentifyFrame))); driver .findElement (By.id(locatorToCloseAd)) .click (); //Close Ad driver .switchTo () .defaultContent (); // Return to main window Assuming the ad in the  window , follow the below approach: String mainWinHandle = driver.getWindo...

How to handle downloading of different browser drivers without manual intervention?

 Using WebDriverManager, we can automatically download the driver’s binary files (.exe files) for Web Automation Traditionally the binaries are referred as System.setProperty(""""webdriver.chrome.driver"""", """"D:\\test\\chromedriver.exe"""" ); With WebDriverManager, we can eliminate the downloading of the binaries everytime a new version is released. WebDriverManager.chromedriver().setup(); POM: <dependency>   <groupId>io.github.bonigarcia</groupId>   <artifactId>webdrivermanager</artifactId>     <version>3.0.0</version>   <scope>test</scope> </dependency>""