How to use serialize_argument method in Playwright Python

Best Python code snippet using playwright-python

_frame.py

Source:_frame.py Github

copy

Full Screen

...178 await self._channel.send(179 "evaluateExpression",180 dict(181 expression=expression,182 arg=serialize_argument(arg),183 ),184 )185 )186 async def evaluate_handle(187 self, expression: str, arg: Serializable = None188 ) -> JSHandle:189 return from_channel(190 await self._channel.send(191 "evaluateExpressionHandle",192 dict(193 expression=expression,194 arg=serialize_argument(arg),195 ),196 )197 )198 async def query_selector(self, selector: str) -> Optional[ElementHandle]:199 return from_nullable_channel(200 await self._channel.send("querySelector", dict(selector=selector))201 )202 async def query_selector_all(self, selector: str) -> List[ElementHandle]:203 return list(204 map(205 cast(ElementHandle, from_channel),206 await self._channel.send("querySelectorAll", dict(selector=selector)),207 )208 )209 async def wait_for_selector(210 self,211 selector: str,212 timeout: float = None,213 state: Literal["attached", "detached", "hidden", "visible"] = None,214 ) -> Optional[ElementHandle]:215 return from_nullable_channel(216 await self._channel.send("waitForSelector", locals_to_params(locals()))217 )218 async def is_checked(self, selector: str, timeout: float = None) -> bool:219 return await self._channel.send("isChecked", locals_to_params(locals()))220 async def is_disabled(self, selector: str, timeout: float = None) -> bool:221 return await self._channel.send("isDisabled", locals_to_params(locals()))222 async def is_editable(self, selector: str, timeout: float = None) -> bool:223 return await self._channel.send("isEditable", locals_to_params(locals()))224 async def is_enabled(self, selector: str, timeout: float = None) -> bool:225 return await self._channel.send("isEnabled", locals_to_params(locals()))226 async def is_hidden(self, selector: str, timeout: float = None) -> bool:227 return await self._channel.send("isHidden", locals_to_params(locals()))228 async def is_visible(self, selector: str, timeout: float = None) -> bool:229 return await self._channel.send("isVisible", locals_to_params(locals()))230 async def dispatch_event(231 self, selector: str, type: str, eventInit: Dict = None, timeout: float = None232 ) -> None:233 await self._channel.send(234 "dispatchEvent",235 dict(selector=selector, type=type, eventInit=serialize_argument(eventInit)),236 )237 async def eval_on_selector(238 self,239 selector: str,240 expression: str,241 arg: Serializable = None,242 ) -> Any:243 return parse_result(244 await self._channel.send(245 "evalOnSelector",246 dict(247 selector=selector,248 expression=expression,249 arg=serialize_argument(arg),250 ),251 )252 )253 async def eval_on_selector_all(254 self,255 selector: str,256 expression: str,257 arg: Serializable = None,258 ) -> Any:259 return parse_result(260 await self._channel.send(261 "evalOnSelectorAll",262 dict(263 selector=selector,264 expression=expression,265 arg=serialize_argument(arg),266 ),267 )268 )269 async def content(self) -> str:270 return await self._channel.send("content")271 async def set_content(272 self,273 html: str,274 timeout: float = None,275 waitUntil: DocumentLoadState = None,276 ) -> None:277 await self._channel.send("setContent", locals_to_params(locals()))278 @property279 def name(self) -> str:280 return self._name or ""281 @property282 def url(self) -> str:283 return self._url or ""284 @property285 def parent_frame(self) -> Optional["Frame"]:286 return self._parent_frame287 @property288 def child_frames(self) -> List["Frame"]:289 return self._child_frames.copy()290 def is_detached(self) -> bool:291 return self._detached292 async def add_script_tag(293 self,294 url: str = None,295 path: Union[str, Path] = None,296 content: str = None,297 type: str = None,298 ) -> ElementHandle:299 params = locals_to_params(locals())300 if path:301 with open(path, "r") as file:302 params["content"] = file.read() + "\n//# sourceURL=" + str(Path(path))303 del params["path"]304 return from_channel(await self._channel.send("addScriptTag", params))305 async def add_style_tag(306 self, url: str = None, path: Union[str, Path] = None, content: str = None307 ) -> ElementHandle:308 params = locals_to_params(locals())309 if path:310 with open(path, "r") as file:311 params["content"] = (312 file.read() + "\n/*# sourceURL=" + str(Path(path)) + "*/"313 )314 del params["path"]315 return from_channel(await self._channel.send("addStyleTag", params))316 async def click(317 self,318 selector: str,319 modifiers: List[KeyboardModifier] = None,320 position: Position = None,321 delay: float = None,322 button: MouseButton = None,323 clickCount: int = None,324 timeout: float = None,325 force: bool = None,326 noWaitAfter: bool = None,327 ) -> None:328 await self._channel.send("click", locals_to_params(locals()))329 async def dblclick(330 self,331 selector: str,332 modifiers: List[KeyboardModifier] = None,333 position: Position = None,334 delay: float = None,335 button: MouseButton = None,336 timeout: float = None,337 force: bool = None,338 noWaitAfter: bool = None,339 ) -> None:340 await self._channel.send("dblclick", locals_to_params(locals()))341 async def tap(342 self,343 selector: str,344 modifiers: List[KeyboardModifier] = None,345 position: Position = None,346 timeout: float = None,347 force: bool = None,348 noWaitAfter: bool = None,349 ) -> None:350 await self._channel.send("tap", locals_to_params(locals()))351 async def fill(352 self, selector: str, value: str, timeout: float = None, noWaitAfter: bool = None353 ) -> None:354 await self._channel.send("fill", locals_to_params(locals()))355 async def focus(self, selector: str, timeout: float = None) -> None:356 await self._channel.send("focus", locals_to_params(locals()))357 async def text_content(self, selector: str, timeout: float = None) -> Optional[str]:358 return await self._channel.send("textContent", locals_to_params(locals()))359 async def inner_text(self, selector: str, timeout: float = None) -> str:360 return await self._channel.send("innerText", locals_to_params(locals()))361 async def inner_html(self, selector: str, timeout: float = None) -> str:362 return await self._channel.send("innerHTML", locals_to_params(locals()))363 async def get_attribute(364 self, selector: str, name: str, timeout: float = None365 ) -> Optional[str]:366 return await self._channel.send("getAttribute", locals_to_params(locals()))367 async def hover(368 self,369 selector: str,370 modifiers: List[KeyboardModifier] = None,371 position: Position = None,372 timeout: float = None,373 force: bool = None,374 ) -> None:375 await self._channel.send("hover", locals_to_params(locals()))376 async def select_option(377 self,378 selector: str,379 value: Union[str, List[str]] = None,380 index: Union[int, List[int]] = None,381 label: Union[str, List[str]] = None,382 element: Union["ElementHandle", List["ElementHandle"]] = None,383 timeout: float = None,384 noWaitAfter: bool = None,385 ) -> List[str]:386 params = locals_to_params(387 dict(388 selector=selector,389 timeout=timeout,390 noWaitAfter=noWaitAfter,391 **convert_select_option_values(value, index, label, element),392 )393 )394 return await self._channel.send("selectOption", params)395 async def set_input_files(396 self,397 selector: str,398 files: Union[str, Path, FilePayload, List[Union[str, Path]], List[FilePayload]],399 timeout: float = None,400 noWaitAfter: bool = None,401 ) -> None:402 params = locals_to_params(locals())403 params["files"] = normalize_file_payloads(files)404 await self._channel.send("setInputFiles", params)405 async def type(406 self,407 selector: str,408 text: str,409 delay: float = None,410 timeout: float = None,411 noWaitAfter: bool = None,412 ) -> None:413 await self._channel.send("type", locals_to_params(locals()))414 async def press(415 self,416 selector: str,417 key: str,418 delay: float = None,419 timeout: float = None,420 noWaitAfter: bool = None,421 ) -> None:422 await self._channel.send("press", locals_to_params(locals()))423 async def check(424 self,425 selector: str,426 timeout: float = None,427 force: bool = None,428 noWaitAfter: bool = None,429 ) -> None:430 await self._channel.send("check", locals_to_params(locals()))431 async def uncheck(432 self,433 selector: str,434 timeout: float = None,435 force: bool = None,436 noWaitAfter: bool = None,437 ) -> None:438 await self._channel.send("uncheck", locals_to_params(locals()))439 async def wait_for_timeout(self, timeout: float) -> None:440 await self._connection._loop.create_task(asyncio.sleep(timeout / 1000))441 async def wait_for_function(442 self,443 expression: str,444 arg: Serializable = None,445 timeout: float = None,446 polling: Union[float, Literal["raf"]] = None,447 ) -> JSHandle:448 params = locals_to_params(locals())449 params["arg"] = serialize_argument(arg)450 return from_channel(await self._channel.send("waitForFunction", params))451 async def title(self) -> str:...

Full Screen

Full Screen

_element_handle.py

Source:_element_handle.py Github

copy

Full Screen

...65 async def is_visible(self) -> bool:66 return await self._channel.send("isVisible")67 async def dispatch_event(self, type: str, eventInit: Dict = None) -> None:68 await self._channel.send(69 "dispatchEvent", dict(type=type, eventInit=serialize_argument(eventInit))70 )71 async def scroll_into_view_if_needed(self, timeout: float = None) -> None:72 await self._channel.send("scrollIntoViewIfNeeded", locals_to_params(locals()))73 async def hover(74 self,75 modifiers: List[KeyboardModifier] = None,76 position: Position = None,77 timeout: float = None,78 force: bool = None,79 ) -> None:80 await self._channel.send("hover", locals_to_params(locals()))81 async def click(82 self,83 modifiers: List[KeyboardModifier] = None,84 position: Position = None,85 delay: float = None,86 button: MouseButton = None,87 clickCount: int = None,88 timeout: float = None,89 force: bool = None,90 noWaitAfter: bool = None,91 ) -> None:92 await self._channel.send("click", locals_to_params(locals()))93 async def dblclick(94 self,95 modifiers: List[KeyboardModifier] = None,96 position: Position = None,97 delay: float = None,98 button: MouseButton = None,99 timeout: float = None,100 force: bool = None,101 noWaitAfter: bool = None,102 ) -> None:103 await self._channel.send("dblclick", locals_to_params(locals()))104 async def select_option(105 self,106 value: Union[str, List[str]] = None,107 index: Union[int, List[int]] = None,108 label: Union[str, List[str]] = None,109 element: Union["ElementHandle", List["ElementHandle"]] = None,110 timeout: float = None,111 noWaitAfter: bool = None,112 ) -> List[str]:113 params = locals_to_params(114 dict(115 timeout=timeout,116 noWaitAfter=noWaitAfter,117 **convert_select_option_values(value, index, label, element)118 )119 )120 return await self._channel.send("selectOption", params)121 async def tap(122 self,123 modifiers: List[KeyboardModifier] = None,124 position: Position = None,125 timeout: float = None,126 force: bool = None,127 noWaitAfter: bool = None,128 ) -> None:129 await self._channel.send("tap", locals_to_params(locals()))130 async def fill(131 self, value: str, timeout: float = None, noWaitAfter: bool = None132 ) -> None:133 await self._channel.send("fill", locals_to_params(locals()))134 async def select_text(self, timeout: float = None) -> None:135 await self._channel.send("selectText", locals_to_params(locals()))136 async def set_input_files(137 self,138 files: Union[str, Path, FilePayload, List[Union[str, Path]], List[FilePayload]],139 timeout: float = None,140 noWaitAfter: bool = None,141 ) -> None:142 params = locals_to_params(locals())143 params["files"] = normalize_file_payloads(files)144 await self._channel.send("setInputFiles", params)145 async def focus(self) -> None:146 await self._channel.send("focus")147 async def type(148 self,149 text: str,150 delay: float = None,151 timeout: float = None,152 noWaitAfter: bool = None,153 ) -> None:154 await self._channel.send("type", locals_to_params(locals()))155 async def press(156 self,157 key: str,158 delay: float = None,159 timeout: float = None,160 noWaitAfter: bool = None,161 ) -> None:162 await self._channel.send("press", locals_to_params(locals()))163 async def check(164 self, timeout: float = None, force: bool = None, noWaitAfter: bool = None165 ) -> None:166 await self._channel.send("check", locals_to_params(locals()))167 async def uncheck(168 self, timeout: float = None, force: bool = None, noWaitAfter: bool = None169 ) -> None:170 await self._channel.send("uncheck", locals_to_params(locals()))171 async def bounding_box(self) -> Optional[FloatRect]:172 return await self._channel.send("boundingBox")173 async def screenshot(174 self,175 timeout: float = None,176 type: Literal["jpeg", "png"] = None,177 path: Union[str, Path] = None,178 quality: int = None,179 omitBackground: bool = None,180 ) -> bytes:181 params = locals_to_params(locals())182 if "path" in params:183 del params["path"]184 encoded_binary = await self._channel.send("screenshot", params)185 decoded_binary = base64.b64decode(encoded_binary)186 if path:187 with open(path, "wb") as fd:188 fd.write(decoded_binary)189 return decoded_binary190 async def query_selector(self, selector: str) -> Optional["ElementHandle"]:191 return from_nullable_channel(192 await self._channel.send("querySelector", dict(selector=selector))193 )194 async def query_selector_all(self, selector: str) -> List["ElementHandle"]:195 return list(196 map(197 cast(Callable[[Any], Any], from_nullable_channel),198 await self._channel.send("querySelectorAll", dict(selector=selector)),199 )200 )201 async def eval_on_selector(202 self,203 selector: str,204 expression: str,205 arg: Serializable = None,206 ) -> Any:207 return parse_result(208 await self._channel.send(209 "evalOnSelector",210 dict(211 selector=selector,212 expression=expression,213 arg=serialize_argument(arg),214 ),215 )216 )217 async def eval_on_selector_all(218 self,219 selector: str,220 expression: str,221 arg: Serializable = None,222 ) -> Any:223 return parse_result(224 await self._channel.send(225 "evalOnSelectorAll",226 dict(227 selector=selector,228 expression=expression,229 arg=serialize_argument(arg),230 ),231 )232 )233 async def wait_for_element_state(234 self,235 state: Literal[236 "disabled", "editable", "enabled", "hidden", "stable", "visible"237 ],238 timeout: float = None,239 ) -> None:240 await self._channel.send("waitForElementState", locals_to_params(locals()))241 async def wait_for_selector(242 self,243 selector: str,...

Full Screen

Full Screen

program.py

Source:program.py Github

copy

Full Screen

...170 if isinstance(value, six.string_types):171 return '"{}"'.format(value)172 else:173 return str(value)174 def serialize_argument(argument, command):175 # type: (Argument, Command) -> str176 if isinstance(argument, ListArgument):177 return "[{}]".format(178 ", ".join(179 serialize_value(x, argument, command) for x in argument.value180 )181 )182 elif isinstance(argument.value, dict):183 return "[\n{}\n ]".format(184 ",\n".join(185 ' "{}": "{}"'.format(key, value)186 for key, value in argument.value.items()187 )188 )189 return serialize_value(argument.value, argument, command)190 def serialize_command(command):191 # type: (Command) -> str192 return "{} = {}({})".format(193 command.result_name,194 command.name,195 "\n {}\n".format(196 ",\n ".join(197 "{} = {}".format(a.name, serialize_argument(a, command))198 for a in command.arguments199 )200 ),201 )202 return "\n".join(203 serialize_command(command) for command in self.commands.values()204 )205 def to_file(self, file_or_path):206 # type: (Union[TextIO, str]) -> None207 """ Writes the program as an MPilot command file. """208 if hasattr(file_or_path, "write"):209 f = file_or_path210 else:211 f = open(file_or_path, "w")...

Full Screen

Full Screen

decorator.py

Source:decorator.py Github

copy

Full Screen

...55 name: ClassVar[str] = decorator.func.name56 Parameters = decorator.generate_parameter_class()57 def specify_manifest(self) -> v1alpha1.ScriptTemplate:58 return v1alpha1.ScriptTemplate(image=self.image, source=source, command=["bash"])59 def serialize_argument(self, argument: Any) -> str:60 return decorator.serialize_argument(argument)61 return Script62 def generate_source(self) -> str:63 return self.func.docstring or self.func.return_value or ""64 def serialize_argument(self, argument: Any) -> str:65 return str(argument)66script_template = ScriptDecorator67class BashDecorator(ScriptDecorator):68 command: str = "bash"69 def generate_source(self) -> str:70 source = super().generate_source()71 parameters = ['%s="{{inputs.parameters.%s}}"' % (parameter, parameter) for parameter in self.func.parameters]72 source = "\n".join(parameters) + "\n" + source73 return source74bash_template = BashDecorator75class PythonDecorator(ScriptDecorator):76 command: str = "python"77 pickle_protocol: Optional[int] = None78 def generate_source(self) -> str:79 source = self.func.body.strip()80 parameter_class = self.func.parameter_class81 is_value_from_param = lambda name, annotation: annotation == v1alpha1.ValueFrom or isinstance(82 getattr(parameter_class, name, None), v1alpha1.ValueFrom83 )84 codes = []85 for param_name, param_annotation in parameter_class.__annotations__.items():86 if is_value_from_param(param_name, param_annotation) or param_annotation == str:87 codes.append('%s = "{{inputs.parameters.%s}}"' % (param_name, param_name))88 elif param_annotation in [int, float, bool, complex]:89 codes.append("%s = {{inputs.parameters.%s}}" % (param_name, param_name))90 else:91 if codes[0] != "import pickle":92 codes = ["import pickle"] + codes93 codes.append(94 '%s = pickle.loads(bytearray.fromhex("{{inputs.parameters.%s}}"), protocol=%s)'95 % (param_name, param_name, self.pickle_protocol)96 )97 if self.func.parameters:98 source = "\n".join(codes) + f"\n\n{source}"99 return source100 def generate_parameter_class(self) -> Type:101 parameter_class = self.func.parameter_class102 if not self.func.parameters:103 return parameter_class104 annotations = dict(parameter_class.__annotations__)105 def serialize_default_value(v: Any):106 if isinstance(v, v1alpha1.ValueFrom):107 return v108 else:109 return self.serialize_argument(v)110 default_fields: Dict[str, Any] = {111 k: serialize_default_value(v) for k, v in parameter_class.__dict__.items() if not k.startswith("_")112 }113 return type("Parameters", (), {"__annotations__": annotations, **default_fields})114 def serialize_argument(self, argument: Any) -> str:115 if isinstance(argument, (str, int, float, bool, complex)):116 return str(argument)117 else:118 return str(pickle.dumps(argument, protocol=self.pickle_protocol).hex())119python_template = PythonDecorator120class ResourceDecorator(TemplateDecorator[ResourceTemplate]):121 action: Literal["get", "create", "apply", "delete", "replace", "patch"]122 resource_manifest: Optional[str] = None123 failureCondition: Optional[str] = None124 flags: Optional[List[str]] = None125 mergeStrategy: Optional[Literal["strategic", "merge", "json"]] = None126 setOwnerReference: Optional[bool] = None127 successCondition: Optional[str] = None128 def generate_template(self) -> Type[ResourceTemplate]:...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful