How to use set_viewport_size method in Playwright Python

Best Python code snippet using playwright-python

LOL.py

Source:LOL.py Github

copy

Full Screen

...7"""8from scrapy_splash import SplashRequest9"""10script1: LUA语法脚本11 set_viewport_size(w, h): 用来设置浏览器页面的宽高;12 go(): 完成指定页面的加载;13 参数: url, baseurl, headers, http_method, body, formdata14 url: 需要加载的页面的网址;15 baseurl: 可选参数,默认为空,表示资源加载的相对路径;16 headers: 可选参数,默认为空,用来设置请求的header;17 http_method: 可选参数,默认为get,如果是post此时需要设置;18 body: 可选参数,默认为空,发送POST请求时向服务器传输的参数数据;19 formdata: 可选参数,默认为空,POST请求时的对应的表单数据,20 默认使用form表单默认的编码格式即application/x-www-form-urlencode.21 wait(): 用来等待网页的加载,单位为秒;22 参数: time, cancle_on_redirect, cancel_on_error 23 time: 延时时间;24 cancel_on_redirect: 可选参数,默认为false,用来设置当网页发生重定向时是否结束等待;25 cancel_on_error: 可选参数,默认为false,用来设置当网页发生错误时是否结束等待26 png(): 将加载之后的网站截屏,以png格式返回, 还有jpeg();27 html(): 将加载之后的网站以HTML格式返回28 29 jsfunc(): 将自定的javascript方法转化成LUA方法,但是自定义方法必须包含在[[]]中30 autoload(): 完成第三方资源远程链接,比如引入Jquery31"""32# 定义一段LUA脚本,控制页面行为33script1 = """34 function main(splash, args)35 splash:set_viewport_size(1200, 2000)36 splash.images_enabled = false37 splash:autoload('https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js')38 splash:go(args.url)39 splash:wait(args.wait)40 click_fun = splash:jsfunc([[41 function(){42 $('label[data-id="Tank"]').click();43 } 44 ]])45 click_fun()46 splash:wait(args.wait)47 return splash:png()48 end49"""50"""51返回字典类型数据时需要使用lxml的etree解析52"""53script2 = """54 function main(splash, args)55 splash:set_viewport_size(1200, 2000)56 splash:go(args.url)57 splash:wait(args.wait)58 return {'msg'='aa', data=splash.html()}59 end60"""61script3 = """62 function main(splash, args)63 splash:set_viewport_size(1200, 2000)64 splash.images_enabled = false65 splash:go("https://lol.qq.com/data/info-defail.shtml?id=Aatrox")66 splash:wait(args.wait)67 return splash:png()68 end69"""70class LolSpider(scrapy.Spider):71 name = 'LOL'72 allowed_domains = ['lol.qq.com']73 start_urls = ['http://lol.qq.com/data/info-heros.shtml']74 def start_requests(self):75 for url in self.start_urls:76 """77 endpoint: 设置splash渲染的方式,默认是render...

Full Screen

Full Screen

lua_js.py

Source:lua_js.py Github

copy

Full Screen

1"""2set_viewport_size(w,h):用来设置浏览器窗口的尺寸,w代表宽度,h代表高度3go(url, baseurl, headers, http_method, body,formdata):完成指定页面的加载4url:需要加载的页面的网址5baseurl:可选参数,默认为空,表示资源加载的相对路径6headers:可选参数,默认为空,用来设置请求的header7http_method:可选参数,默认为get,如果是post此时需要设置8body:可选参数,默认为空,发送POST请求时向服务器传输的参数数据9formdata:可选参数,默认为空,POST的时候对应的表单数据,默认使用form表单默认的编码格式即application/x-www-form-urlencode10wait(time, cancle_on_redirect, cancel_on_error):用来等待网页的加载,对应的时间以秒为单位11time:等待网页加载的时间12cancle_on_redirect:可选参数,默认为false,用来设置当网页发生重定向时是否结束等待13cancle_on_error:可选参数,默认为false,用来设置当网页发生错误时是否结束等待14png():将加载之后的网站截屏,并且以png格式返回15html():将加载之后的网站以html格式返回16jpeg():将加载之后的网站截屏并且以jpg格式返回17jsfunc():将自定的javascript方法转化成lua方法, 但是自定义方法必须包含在[[]]中18autoload():完成第三方资源远程链接加载19"""20lua1='''21 function main(splash,args)22 splash:set_viewport_size(1500,3500)23 splash:go(args.url)24 splash:wait(args.wait)25 26 scrool_top=splash:jsfunc([[27 function(x,y){28 window.scrollTO(x,y)29 }30 ]])31 scrool_top(0,500)32 splash:wait(args.wait/3)33 return {model_name=args.model_name,data=splash:html()}34 end35'''36#定义lua语法模拟用户在英雄页面点击操作37lua_hero='''38 function main(splash,args)39 splash:set_viewport_size(1200,2500)40 splash:autoload("https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js")41 splash:go(args.url)42 splash:wait(args.wait)43 44 click_btn=splash:jsfunc([[45 function(btn_sel){46 $(btn_sel).click();47 }48 ]])49 result={model_name=args.model_name}50 for key,value in pairs(args.kind_dic) do51 sel=string.format('label[data-id=%s]',key)52 click_btn(sel)53 splash:wait(args.wait/2)...

Full Screen

Full Screen

controllers.py

Source:controllers.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from openerp import http3from openerp.addons.web.http import request4class SurveyExtend(http.Controller):5 """extend survey feature"""6 @http.route(['/survey_extend/print/<model("survey.survey"):survey>',7 '/survey_extend/print/<model("survey.survey"):survey>/<string:token>'],8 type='http', auth="public", website=True)9 def view(self, survey, token=None, **post):10 """print survey to pdf11 Arguments:12 survey {[model]} -- survey.survey model13 **post {[dict]} -- other parameter14 Keyword Arguments:15 token {[string]} -- token for this user_line (default: {None})16 Returns:17 [application/pdf] -- print pdf or http status code 40418 """19 if survey:20 if token:21 user_input = survey.user_input_ids.search(22 [('token', '=', token)])23 # user_input = http.request.env['survey.user_input'].search([('token', '=', token)])24 pdf = http.request.env['report'].sudo().with_context(set_viewport_size=True).get_pdf(25 user_input, 'survey_extend.survey_report_user_print')26 else:27 pdf = http.request.env['report'].sudo().with_context(28 set_viewport_size=True).get_pdf(survey, 'survey_extend.survey_report_print')29 pdfhttpheaders = [('Content-Type', 'application/pdf'),30 ('Content-Length', len(pdf))]31 return request.make_response(pdf, headers=pdfhttpheaders)...

Full Screen

Full Screen

report.py

Source:report.py Github

copy

Full Screen

1# Copyright 2017 Avoin.Systems2# Copyright 2017 Eficent Business and IT Consulting Services, S.L.3# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).4from odoo import api, models5class IrActionsReport(models.Model):6 _inherit = 'ir.actions.report'7 @api.model8 def _build_wkhtmltopdf_args(9 self,10 paperformat_id,11 landscape,12 specific_paperformat_args=None,13 set_viewport_size=False):14 # noinspection PyUnresolvedReferences,PyProtectedMember15 command_args = super(IrActionsReport, self)._build_wkhtmltopdf_args(16 paperformat_id,17 landscape,18 specific_paperformat_args,19 set_viewport_size20 )21 for param in paperformat_id.custom_params:22 command_args.extend([param.name])23 if param.value:24 command_args.extend([param.value])...

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