KEMBAR78
Object | PDF | Inheritance (Object Oriented Programming) | Method (Computer Programming)
0% found this document useful (0 votes)
4 views3 pages

Object

The document outlines key Object-Oriented Programming (OOP) concepts such as classes, objects, encapsulation, inheritance, polymorphism, abstraction, method overloading, method overriding, constructors, and destructors, which are essential for interviews. It also introduces the Page Object Model (POM) design pattern used in test automation, emphasizing its benefits like separation of concerns, reusability, and enhanced maintainability. A simplified example of a LoginPage class in JavaScript illustrates how POM organizes test code by encapsulating page elements and functionality.

Uploaded by

IzabellaMolnar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Object

The document outlines key Object-Oriented Programming (OOP) concepts such as classes, objects, encapsulation, inheritance, polymorphism, abstraction, method overloading, method overriding, constructors, and destructors, which are essential for interviews. It also introduces the Page Object Model (POM) design pattern used in test automation, emphasizing its benefits like separation of concerns, reusability, and enhanced maintainability. A simplified example of a LoginPage class in JavaScript illustrates how POM organizes test code by encapsulating page elements and functionality.

Uploaded by

IzabellaMolnar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object-Oriented Programming (OOP) concepts that you might encounter in an interview:

1. Class: A class is a blueprint for creating objects (instances) which defines its properties
(attributes) and behaviors (methods).

2. Object: An object is an instance of a class. It encapsulates data (attributes) and behaviors


(methods).

3. Encapsulation: Encapsulation is the bundling of data and methods that operate on the data
within a single unit, typically a class. It hides the internal state of an object and only exposes
the necessary functionality.

4. Inheritance: Inheritance is a mechanism in which a new class (subclass/derived class) is


created from an existing class (superclass/base class), acquiring the properties and behaviors
of the superclass. It promotes code reuse and establishes an "is-a" relationship.

5. Polymorphism: Polymorphism allows objects of different classes to be treated as objects of


a common superclass. It enables methods to behave differently based on the object they are
invoked upon, enhancing flexibility and extensibility.

6. Abstraction: Abstraction involves focusing on the essential attributes and behaviors of an


object while hiding unnecessary details. It simplifies complex systems by providing a clear
and concise interface for interacting with objects.

7. Method Overloading: Method overloading is the ability to define multiple methods with the
same name but different parameters within a class. It allows for the same method name to
perform different actions based on the input parameters.

8. Method Overriding: Method overriding occurs when a subclass provides a specific


implementation of a method that is already defined in its superclass. It allows for the
subclass to provide its own behavior while maintaining the same method signature as the
superclass.

9. Constructor: A constructor is a special method within a class that is automatically called


when an object of that class is instantiated. It is used to initialize the object's state.

10. Destructor: A destructor is a special method within a class that is called when an object is
destroyed or goes out of scope. It is used to perform cleanup tasks such as releasing
resources.

Understanding these fundamental concepts will provide you with a solid foundation for discussing
Object-Oriented Programming during interviews. Make sure to also practice implementing these
concepts in a programming language of your choice to reinforce your understanding.

basic oop examples in javascript


The Page Object Model (POM) is a design pattern commonly used in test automation to enhance the
maintainability, scalability, and reusability of automated tests. It helps organize test code by
representing web pages as objects, with each page encapsulating its elements and functionality.
Here's an overview of how the Page Object Model works:

1. **Page Objects**: In the POM, each web page in the application under test is represented as a
separate class called a "Page Object." Each Page Object contains locators (e.g., XPath, CSS selectors)
for the elements on that page and methods to interact with those elements.

2. **Separation of Concerns**: The POM promotes a separation of concerns by keeping test code
(e.g., test scripts, assertions) separate from the details of the UI. Test scripts interact with Page
Objects rather than directly interacting with web elements, making the tests more readable and
maintainable.

3. **Reusable Components**: Page Objects encapsulate the behavior of individual pages, making
them reusable across multiple tests. If the UI changes, only the corresponding Page Object needs to
be updated, reducing maintenance effort.

4. **Abstraction of Test Logic**: Page Objects abstract away the complexity of interacting with the
UI, providing a clear and concise interface for test scripts. Test scripts focus on high-level test logic,
while the implementation details are encapsulated within the Page Objects.

5. **Enhanced Readability and Maintainability**: By organizing test code into Page Objects, tests
become more readable, modular, and easier to maintain. Test scripts are more concise and
expressive, leading to improved code quality and reduced duplication.

Here's a simplified example of a Page Object for a login page in a web application:

```javascript

class LoginPage {

constructor() {

this.usernameInput = $('#username');

this.passwordInput = $('#password');
this.loginButton = $('#login-button');

// Methods to interact with page elements

enterUsername(username) {

this.usernameInput.setValue(username);

enterPassword(password) {

this.passwordInput.setValue(password);

clickLoginButton() {

this.loginButton.click();

// Other methods related to login functionality (e.g., error handling)

module.exports = new LoginPage();

```

In this example, the `LoginPage` class represents the login page of the application. It contains
locators for the username input field, password input field, and login button, as well as methods to
interact with these elements (e.g., entering username/password, clicking login button). Test scripts
can then use these methods to perform login actions without needing to know the implementation
details of the page.

You might also like