You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Use Object.hasOwn to check Object properties in JavaScript
2
+
3
+
The `Object.hasOwn()` is a modern JavaScript feature that allows you to check if a given property exists in an object. It's recommended over the `Object.prototype.hasOwnProperty()` function since [it's safer and more intuitive](<https://igorgonchar.medium.com/javascript-hasown-new-way-to-check-if-object-has-property-b93810e47070#:~:text=The%20main%20difference%20is%20that,checks%20only%20the%20object%20itself.&text=hasOwnProperty()%20besides%20focusing%20only,also%20omits%20getters%20and%20setters.>)
4
+
5
+
For example, if we have a custom object of a person:
6
+
7
+
```js
8
+
constperson= {
9
+
name:'John',
10
+
age:24,
11
+
gender:'male',
12
+
bloodType:'O',
13
+
};
14
+
```
15
+
16
+
We can use `Object.hasOwn()` function to check if the `bloodType` property is present in the `person` object:
17
+
18
+
```js
19
+
Object.hasOwn(person, 'bloodType'); // true
20
+
```
21
+
22
+
The above example would have the same result as calling `Object.proptype.hasOwnerProperty.call(person, 'bloodType');`. However, `Object.hasOwn()` is much shorter and more convenient to use.
23
+
24
+
Here is another example of checking the property in a loop:
-[JavaScript: hasOwn() — new way to check if Object has property](<https://igorgonchar.medium.com/javascript-hasown-new-way-to-check-if-object-has-property-b93810e47070#:~:text=The%20main%20difference%20is%20that,checks%20only%20the%20object%20itself.&text=hasOwnProperty()%20besides%20focusing%20only,also%20omits%20getters%20and%20setters.>)
Copy file name to clipboardExpand all lines: python/use-playwright-codegen-to-automate-ui-interactions.md
+11-15
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,32 @@
1
-
# Use Playwright Codegen to Automatically Record UI Interactions
1
+
# Use Playwright Codegen to Automate UI Interactions
2
2
3
-
Playwright has a neat feature of recording user interaction and automatically
4
-
generate source code for you. This would save you a lot of time and automate many
5
-
of your day to day work if the tasks can be done by a browser.
3
+
Playwright has a useful codegen feature that allows you to record your user interactions and generate source code automatically, saving you time and effort in your day-to-day work. If your tasks can be completed through a browser, Codegen can automate them for you.
6
4
7
-
The following example will show you how to record an UI operation that we visit
8
-
the playwright.dev docs and search for this codegen feature and then move on to
9
-
the next page:
5
+
In the following example, we'll demonstrate how to record an UI interactions that involves visiting the playwright.dev documentation, searching for the Codegen feature docs and navigating to the next page.
10
6
11
-
First, create a venv:
7
+
To get started, create a virtual environment:
12
8
13
9
```sh
14
10
python3 -m venv venv
15
11
```
16
12
17
-
Then, install the package
13
+
Next, install the `pytest-playwright`package:
18
14
19
15
```sh
20
16
pip install pytest-playwright
21
17
```
22
18
23
-
And run the codegen command:
19
+
Then, run the codegen command:
24
20
25
21
```sh
26
22
playwright codegen
27
23
```
28
24
29
-
> Note that you might need to run `playwright install` command if you haven't installed any chromium browser on your machine before
25
+
Note that if you haven't installed any Chromium browser on your machine before, you may need to run the `playwright install` command.
30
26
31
-
After running the codegen, you should now have two browsers opened, one is the main chromium browser and the other is a UI for recorded actions.
27
+
Once you've run the codegen, two browser windows should open - one main Chromium browser and an UI for recording your UI interactions.
32
28
33
-
Here is a piece of code that's generated by the codegen after running thru the actions that we mentioned in the above:
29
+
Here is an example of the code that is generated by the codegen after performing the actions mentioned above:
0 commit comments