
Which language do you use with Playwright?
Usually, Playwright support 4 languages
1 - JavaScript & Typescript
2 - Python
3 - Java
4 - C#
In our project, we use TypeScript and JavaScript with Playwright primarily because it offers the most comprehensive and up-to-date support in the Node.js ecosystem, which Playwright is built upon. Additionally, new features and enhancements are typically introduced first in the JavaScript/TypeScript packages, ensuring we stay aligned with the latest capabilities of the framework.
What is the difference between javascript and typescript
Typing System
JavaScript uses dynamic typing, meaning variable types are determined at runtime and can change as the program executes, which allows flexibility but increases the risk of runtime errors. In contrast, TypeScript uses static typing, where types are defined at compile time using type annotations, helping developers catch errors early during development.
Compilation
JavaScript is interpreted directly by web browsers and doesn't require a compilation step, making it quick to run. TypeScript, however, must be compiled into JavaScript using the TypeScript compiler (tsc) before it can be executed, as browsers do not understand TypeScript natively.
Feature Set
JavaScript supports basic object-oriented and functional programming features but lacks built-in interfaces, generics, or advanced OOP features. TypeScript extends JavaScript by adding these capabilities, enabling developers to build more structured, scalable, and maintainable applications.
Tooling and IDE Support
TypeScript offers superior tooling support, with features like IntelliSense, type checking, auto-completion, and refactoring assistance in modern editors like VS Code. JavaScript has basic support for these features but lacks the advanced static analysis and type-safety benefits TypeScript provides.
Error Detection
In JavaScript, most errors are discovered only during runtime, which may lead to bugs in production if not caught through thorough testing. TypeScript detects many potential issues during compilation, reducing runtime failures and improving overall code reliability.
I have an int array
const arr = [0,0,1,2,0,0,3,4,0,5,6,0,0,7,8,0,9]
write a javascript code to arrange all zero in the last
output should be
[1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,0]
I have an int array
const arr = [0,0,1,2,0,0,3,4,0,5,6,0,0,7,8,0,9]
write a javascript code to arrange all zero in the start and rest number should sort in descending order
output should be
[0,0,0,0,0,0,0,0,9,8,7,6,5,4,3,2,1]
How to handle frame in playwright ?
Using frameLocator() (Recommended - Auto-waiting)
#myFrameis theidor selector for the<iframe>.- This method is robust and automatically waits for the frame and the element.
Using page.frame() (Manual access)
Using elementHandle.contentFrame()
How to handle parallel execution in playwright ?
1 - Using playwright.config.ts:
Command prompt/ Shell:
2 - Parallel Tests Within a File
Use test.describe.parallel() to run test cases inside the same file concurrently:
How to handle file upload in playwright ?
1. Basic File Upload
This sets the file input with a local file (must exist on disk).
2. Upload Multiple Files
3. Clear File Input (Remove Uploaded Files)
4. Using File Upload in a Form
5. File Upload Inside an iframe
6. File Upload Using frameLocator (Recommended for Stability)
How to handle exceptions in playwright?
1. Try-Catch Block
Use this to handle any unexpected errors during a test step.
2. Handling Timeout Errors
Set custom timeouts and catch when elements are not available in time.
3. Handling Page Errors (JavaScript Errors on the Page)
You can listen to page-level errors using the page.on('pageerror') event.
4. Handling Request/Response Failures
You can listen for network-related errors.
5. Custom Error Handling
You can throw your own errors for specific business logic.
6. Global Error Handling in Test Frameworks
If you're using Playwright Test:
How to execute test cases in headless and headed mode in playwright?
1. Using the CLI
Headless Mode (default)
By default, Playwright runs tests in headless mode.
You can also explicitly specify it:
Headed Mode (for debugging or visual run)
2. Modify in the playwright.config.ts or playwright.config.js
You can configure it permanently in your Playwright config file.
playwright.config.ts
3. Override in Individual Test Files
You can also override the headless setting in a test:
4. Using Environment Variables (Optional)
You can create a script in package.json for easy toggli
Suppose you have 2 tables
Employee
EmpID
EmpName
EmpCity
1
Ram Mohan
Pune
2
Ram Krishna
Mumbai
Record
EmpID
Salary
Department
1
30000
IT
2
40000
HR
Write me a query to find all employees salary who name starts with Ram

