Skip to main content

How to define DRIVER.MANAGE().WINDOW().MAXIMIZE() ?

What  is DRIVER.MANAGE().WINDOW().MAXIMIZE() ?





Now we explain why do we write syntax as below:

driver.manage().window().maximize(); // To maxmize
driver.navigate().to("some url"); // To open url
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// To set implicit time



Actually it’s JAVA concept. It is called as method chaining. We will learn about this now.
Some basic Concepts of JAVA:
1. There can be two types of members in a java class. Static and Non-static.
2. Static methods can be called using class name or by creating an object of that class but calling by class name is perfect practice.
3. Non-static members of class can be called only through object of class.
4. A method can return a type. It may be class or interface as well.
#JAVACODE to learn how to call static and non-static methods:
public class Demo {

 void NonStaticMethod()

 {

  System.out.println("Non static method");

 }

 static void StaticMethod()

 {

  System.out.println("static method");

 }

  public static void main(String[] args) {


  Demo.StaticMethod();

  Demo object= new Demo();

  object.NonStaticMethod();

  object.StaticMethod(); // Not preferred 

 }

}

Outout:
static method
Non static method
static method
#JavaCode to understand method chaining:

class AnotherDemo

{

 public NewDemo AnotherDemoMethod()

 {

  System.out.println("AnotherDemoMethod");

  return new NewDemo();

 } 

}

class NewDemo

{

 void NewDemoMethod()

 {

  System.out.println("NewDemoMethod");

 }



}

public class Demo {

 public AnotherDemo DemoMethod()

 {

  System.out.println("DemoMethod");

  return new AnotherDemo();

 }



 public static void main(String[] args) {

  

  Demo DemoObject= new Demo();

  AnotherDemo AnotherDemoObject= DemoObject.DemoMethod();

  NewDemo NewDemoObject= AnotherDemoObject.AnotherDemoMethod();

  NewDemoObject.NewDemoMethod();

  

  // method chaining

  Demo DemoObject1= new Demo();

  DemoObject1.DemoMethod().AnotherDemoMethod().NewDemoMethod(); // Method chaining

  

 }


}
2. Class “Demo” has a method “DemoMethod” which return an object of class “AnotherDemo”.
3. Class “AnotherDemo” has a method “AnotherDemoMethod” which return an object of class “NewDemo”.
4. Class “NewDemo” has a method “NewDemoMethod” which return void.
5. Only class “Demo” has main method and through that method we want to access “NewDemoMethod” of class “NewDemo”.
6. We created an object of “Demo” to access method present in class “Demo”.
Demo DemoObject= new Demo();
7. Now, we will call “DemoMethod” of class “Demo” which returns an object of class “AnotherDemo”, which we can store in a variable of type “AnotherDemo”.

AnotherDemo AnotherDemoObject= DemoObject.DemoMethod();
8. Now what we have?? An object of class “AnotherDemo” means we can access methods of class “AnotherDemo”.
9. We call method “AnotherDemoMethod1” of class “AnotherDemo” which returns an object of class “NewDemo”, which we can store in a variable of type “NewDemo”.
NewDemo NewDemoObject= AnotherDemoObject.AnotherDemoMethod();
10. Now, we can access method of “NewDemo”.
NewDemoObject.NewDemoMethod();
11. So, now we have following lines of code:

Demo DemoObject= new Demo();

AnotherDemo AnotherDemoObject= DemoObject.DemoMethod();

NewDemo NewDemoObject= AnotherDemoObject.AnotherDemoMethod();

NewDemoObject.NewDemoMethod();
13. Above code has concepts of method chaining and anonymous object. When we need to use object once in a program, we can go for anonymous object for better memory utilization.
I hope above java concept must be clear.
Same logic is applied for selenium. I will explain one statement:
driver.manage().window().maximize();
When we call manage() method, it returns a “Options” type. “Options” is an interface.

public Options manage() 

{

return new RemoteWebDriver.RemoteWebDriverOptions();

}
Interface “Options” has method “windows” which returns “Window” type.

public interface Options {

WebDriver.Window window();

}
Now, we can use any method of interface “Window”. it has following methods which can be called.

public interface Window {

  void setSize(Dimension arg0);

  void setPosition(Point arg0);

  Dimension getSize();

  Point getPosition();

  void maximize();

  void fullscreen();

 }
See complete code below:

WebDriver driver= new ChromeDriver();

Options optnObj= driver.manage();

Window winObj= optnObj.window();

winObj.maximize();

  

// We can write above lines of code in one line as

driver.manage().window().maximize();

Comments

Popular posts from this blog

How to analyze a JMeter summary report?

  A  Jmeter  Test Plan must have listener to showcase the result of performance test execution. Listeners capture the response coming back from Server while Jmeter runs and showcase in the form of – tree, tables, graphs and log files. It also allows you to save the result in a file for future reference. There are many types of listeners Jmeter provides. Some of them are: Summary Report, Aggregate Report, Aggregate Graph, View Results Tree, View Results in Table etc. Here is the detailed understanding of each parameter in Summary report. By referring to the figure: Label : It is the name/URL for the specific HTTP(s) Request. If you have selected “Include group name in label?” option then the name of the Thread Group is applied as the prefix to each label. Samples : This indicates the number of virtual users per request. Average : It is the average time taken by all the samples to execute specific label. In our case, the average time for Label 1 is 942 milliseconds & to...

What is usability testing ?

What is usability testing ? Usability testing is a way to see how system is easily usable by the end users. It basically verifies the interface of website and test whether application is user friendly or not. It identifies how the customer will feel comfortable in using the software. Usability Testing not only test Look and feel it also test in how many steps customer will reach their goals Example: Suppose there is an application in which user wants to generate Attendance Report of Employees on daily basis, and user has to follow below steps: 1) Login to Application. 2) Click on Attendance System 3) Click on Reports and select Employee Attendance Report 4) Various Employee Attendance reports will be displayed of different teams. Select particular report(say: Select Team) 5) Select the parameters which you want to display in report say: • Date • Shift Timings • Employee Id • Name • In/Out Time • Status (Present/Absent/leave) 6) Click on Generate Report 7) Click on Print option In this ...

What is Error, Bug and Defec ?

What is Error, Bug and Defect in software testing ? Error :- When developer compile a program and program compilation is failed due to some syntax problem or not used correct logic, is called an Error.  For example:-  public class  { public static void main( string []args) { s.o.p(" hello") } } Now after running this program, we will get an error because there is syntax issues as we haven't use correct syntax to print output. Bug : Bug is something that is not producing expected output or something is not behaving as expected.  For example- Developer develop a program to add two number and that program is running fine but producing wrong result. public class  { public static void main( string []args) { int a=3; int b=2; int s= ++a+b; System.out.println(" hello"); } } Actual output: 6 Expected outpit: 5 So here system is not producing expected output after adding two number. In simple term, whe...