JS for Testers Part-2

Agenda

  • Recap of Part-1
  • Review for API Assignment
  • Tour of WordPress Application
  • Anti-Pattern in PageObjects
  • SOLID Principles
  • Clean Code 
  • Design Patterns
  • Design FrameWork using Taiko and API

Part 1

  • Data Types
  • Functions
  • Objects
  • Classes
  • Modules
  • Promises
  • Async
  • Await

API Assignment Review

Page Object Pattern


public class LoginPage extends Page {
	
	//WebElements
	@FindBy(using = "user_name")
	@CacheLookup
	private WebElement userName;

	@FindBy(using = "password")
	@CacheLookup
	private WebElement password;

	@FindBy(css = ".btn.btn-success")
	@CacheLookup
	private WebElement loginbtn;

	public LoginPage(WebDriver webDriver) {
		super(webDriver);
		PageFactory.initElements(webDriver, this);
	}

	//Methods
	@Step
	public HomePage login(String uName, String passw){
		userName.sendKeys(uName);
		password.sendKeys(passw);
		loginbtn.click();
		return new HomePage(webDriver);
	}

}

Clean Code

SOLID Principles

  • S - Single-responsibility principle
  • O - Open-closed principle
  • L - Liskov substitution principle
  • I - Interface segregation principle
  • D - Dependency Inversion Principle

A class should have one and only one reason to change, meaning that a class should have only one job.

Objects or entities should be open for extension but closed for modification.

Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions

D.R.Y - Don’t Repeat Yourself

 

F.I.R.S.T Principles

  • F - Fast
  • I - Isolate
  • R - Repeatable
  • S - Self-validating
  • T - Timely

Design Patterns

Design Patterns are solutions to software design problems in real-world application development. Patterns are about reusable designs and interactions of objects.

Design Patterns

  • Design patterns are not a silver bullet to all your problems.
  • Do not try to force them bad things are supposed to happen, if done so. Keep in mind that design patterns are solutions to problems, not solutions finding problems so don't overthink.
  • If used in a correct place in a correct manner, they can prove to be a savior or else they can result in a horrible mess of a code.

The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized into three groups: Creational, Structural, and Behavioral 

 

  • Creational patterns mostly describe a moment of time (the instant of creation)
  • Structural patterns describe a more or less static structure
  • Behavioral patterns describe a process or a flow

Creational Design Pattern

Deal with object creation mechanisms and are used in situations when the basic form of object creation could result in design problems or increase the complexity of a code base

Structural Design Pattern

Ease the design by identifying a simple way to realize relationships between entities or defines a manner for creating relationships between objects

Behavioral Design Pattern

Explains how objects interact

JS for Testers Part-2

By Sai Krishna

JS for Testers Part-2

  • 521