DAY 6 - Industry Connect
What is design pattern?
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
Uses of Design Patterns
Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.
Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn't require specifics tied to a particular problem.
In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.
Why do we need design pattern in our test suite?
- Design Patterns save time and effort
- It results in low maintenance cost
- Helps in code reusability
- It helps in enhancing reliability.
- Helping us to create a structured code that eases our process of automation.
- It helps in improving communication.
What are the different design patterns for automated tests?
The classes and objects participating in this pattern are:
- Page Object (SearchEngineMainPage)- Contains properties of all necessary web elements of the page. Also, there you can find all actions that can be performed (Search, Navigate). All validations can be placed here too.
- UI Tests (SearchEngineTests) – This class contains a group of tests related to the above page; it can hold only a single instance of the page object.
What is page object model (or POM)?
Page Object Model (POM) is a design pattern, popularly used in test automation that creates Object Repository for web UI elements. The advantage of the model is that it reduces code duplication and improves test maintenance.
Under this model, for each web page in the application, there should be a corresponding Page Class. This Page class will identify the WebElements of that web page and also contains Page methods which perform operations on those WebElements. Name of these methods should be given as per the task they are performing, i.e., if a loader is waiting for the payment gateway to appear, POM method name can be waitForPaymentScreenDisplay().
What is "synchronization" problem in Selenium?
Because the Selenium WebDriver typically has to block APIs, and the web platform is asynchronous, it does not track the state of the DOM in real time.
When operations are done on a web element that is not yet present in the DOM or is not in a position to accept instructions, synchronization issues occur (e.g., not visible, not clickable, etc.).
When the user instructs the browser to travel to a specific page and the Selenium test automation implementation encounters an ElementNotVisibleException while trying to discover a web element, race situations are likely. Selenium’s wait commands can be used to prevent race circumstances between the browser and the Selenium WebDriver script.
Wait instructions in Selenium can be used to handle synchronization, such as waiting for a given duration or for a specific condition to occur.
For test automation, we used the PHPUnit framework. The test execution was successful on the first run, but the second run resulted in an ElementNotInteractableException. As a result, the test scenario’s behavior (i.e., whether it passes or raises “various types” of exceptions) cannot be predicted.
Because there is no guarantee about the web components or events that are triggered asynchronously, without stopping or explicitly waiting on those events, this Selenium WebDriver script may be intermittent. Wait commands in Selenium PHP come in helpful here because they aid with synchronization concerns in Selenium web automation.
For example, the Implicit Wait command specifies a wait time of 30 seconds. The chosen time (30 seconds) is used as the default for all subsequent testSteps, resulting in execution time. Explicit waits were created to address this issue, and they are used to apply waits whenever they are required while running the testSteps.
评论
发表评论