Friday, 24 April 2020

SE - 71 - Interface and its implementations in excel

We have 3 flavours of classes used in excel:

HSSF : To handle .xls type of excel(older versions of excel)

SXSSF : It is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited

XSSF : To handle .xlsx type of excel(newer versions of excel)


Major Interfaces  and Its Implementations :

Row : HSSFRow, SXSSFRow, XSSFRow
Cell : HSSFCell, SXSSFCell, XSSFCell
Sheet : HSSFSheet, SXSSFSheet, XSSFChartSheet, XSSFDialogsheet, XSSFSheet
WorkBook : HSSFWorkbook, SXSSFWorkbook, XSSFWorkbook

SE - 70 - Difference between Click() and Submit() methods in selenium

Both the methods in selenium almost plays a similar role. Submit is specific to some forms in which the internal tag is designed in the way that it has acceptance to Submit() method.

submit()
Submits the element to the web server. If this current element is a form, or an element within a form then this will be submitted to the web server. If this causes the current page to change, then this method will block until the new page is loaded. StaleElementReferenceException is thrown when the target element is no longer valid in the document DOM.



click()
Click on the element. If the click causes a new page to load, the method will attempt to block until the page has loaded. After calling the method, you should discard all references to this element unless you know that the element and the page will still be present. Otherwise, any further operations performed on this element will have undefined behavior. ElementNotVisibleException is thrown when the target element is not visible. StaleElementReferenceException is thrown when the target element is no longer valid in the document DOM(document object model).

SE - 69 - Can constructor throw exception in JAVA ?

YES , Constructor can also throw exceptions like normal method does.


public class ConstructorTest {
   public ConstructorTest() throws InterruptedException {
      System.out.println("Before Sleep");
      Thread.sleep(1000);
      System.out.println("After Sleep");
   }

SE - 68 - To click on hidden link

There are some instances where link is present on DOM but it is hidden. We can't locate it normally and do any operation on it.
On locating it we get ElementnotVisibleException
It is generally made hidden by style="display:none;".

So to handle this situation we need to take support of JavaScriptExecutor.

Code Below :

Example 1 : 
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
Here element is the object of the element we are looking for.
Example 2 : 
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('txt'.value='ABCD'");

Tuesday, 21 April 2020

SE - 66 - Some basics of Selenium!

1) flush() method is used to write any data to file and Length() method is used to get its length

2) If we are writing in preexisting file then it will be overrided. If we want to append it we neet to give Filewriter(name , true)

3) BufferReader/BufferedWriter is wrapper on FileReader/Writer which helps in transmission of data in packets

4) Assertion.assertAll is written at the end of each soft assert to display failed assertions with reasons

5)Implicit wait works on existance of element while Explicit works on existance of property

6) Type of exceptions in failure of implicit and explicit wait
Implicit wait : No such Element
Explicit Wait : TImeout exception

7) While testing with Selenium,we use setProperty method because the browser doesn’t have a built-in server to run the automation code. In this case, we will need a Chrome/IE/Gecko driver server for communicating your Selenium code to the browser. It allows the selenium code to interact with browser.

SE - 65 - Does Abstract class has constructors ?

Ans to this question is Yes . Abstract class can have constructors. Now the question is usage of it because we can't create object of Abstract Class. The abstract class constructor is called when in child class its methods are defined and they are called in another class. When we create an object of any subclass all the constructors in the corresponding inheritance tree are invoked in the top to bottom approach. The same case applies to abstract classes. 

SE - 64 - Output with combination of String , Integer and Character


Let's understand by a program :


public static void main(String[] args) {
  String S1 = " String1 ";
  String S2 = " String2 ";
  
  char c1 = 'a';
  char c2 = 'b';
  
  int i1 = 10;
  int i2 = 20;
  
System.out.println(S1 + c1 + i1);  // String1 a10
System.out.println(c1 + S1 + i1);  // a String1 10
System.out.println(S1 + i1 + i2);  // String1 1020
System.out.println(i1 + i2 + S1);  // 30 String1 
System.out.println(S1 + c1 + c2);  //  String1 ab
System.out.println(S1 + S2 + c1 + c2 + i1 + i2);  // String1  String2 ab1020
System.out.println(i1 + c1 + i2);  // 127
System.out.println(i1 + S1 + i2);  // 10 String1 20
System.out.println(S1 + c1 + S2);  //  String1 a String2 
System.out.println(S1 + i1 + S2);  // String1 10 String2 
System.out.println(S1 + i1 + i2 + S2);  // String1 1020 String2 
System.out.println(S1 + S2);  //  String1  String2 
System.out.println(c1 + c2);  // 195
System.out.println(S1 + c1);  //  String1 a
System.out.println(S1 + i1);  //  String1 10
System.out.println(i1 + c1);  // 107
System.out.println(i1 + c1 + S1);  // 107 String1 
System.out.println(c1 + c2 + S1);  // 195 String1 
}

Excerpts : 
1) If there is char and int combination then the ASCII value of char will be summed up with integer

2) If there is only integer , then it will be summed up.

3) If there is integer before String, then integer will be added up and will be concatenated with string.

4) If there is Integer after string  , then string will be concatenated with int. No addition will happen.

5) Char or Int prior to string will be summed up but if it is after the string it will not be summed up