How to use save_screenshot method in SeleniumBase

Best Python code snippet using SeleniumBase

assignment_5.py

Source: assignment_5.py Github

copy

Full Screen

1import urllib2from selenium import webdriver3driver = webdriver.Chrome()4driver.get("https:/​/​images.unsplash.com/​photo-1579710758949-3ab36db30f1b?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDF8MHxzZWFyY2h8MXx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")5driver.save_screenshot("nature1.png")6driver.get("https:/​/​images.unsplash.com/​photo-1469474968028-56623f02e42e?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")7driver.save_screenshot("nature2.png")8driver.get("https:/​/​images.unsplash.com/​photo-1433086966358-54859d0ed716?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")9driver.save_screenshot("nature3.png")10driver.get("https:/​/​images.unsplash.com/​photo-1501854140801-50d01698950b?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")11driver.save_screenshot("nature4.png")12driver.get("https:/​/​images.unsplash.com/​photo-1447752875215-b2761acb3c5d?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")13driver.save_screenshot("nature5.png")14driver.get("https:/​/​images.unsplash.com/​photo-1470071459604-3b5ec3a7fe05?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")15driver.save_screenshot("nature6.png")16driver.get("https:/​/​images.unsplash.com/​photo-1441974231531-c6227db76b6e?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")17driver.save_screenshot("nature7.png")18driver.get("https:/​/​images.unsplash.com/​photo-1465146344425-f00d5f5c8f07?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTB8fG5hdHVyZXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=1400")19driver.save_screenshot("nature8.png")20driver.get("https:/​/​images.unsplash.com/​photo-1647891940243-77a6483a152e?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDF8MHxzZWFyY2h8OHx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")21driver.save_screenshot("nature9.png")22driver.get("https:/​/​images.unsplash.com/​photo-1426604966848-d7adac402bff?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8bmF0dXJlfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=1400")23driver.save_screenshot("nature10.png")24driver.get("https:/​/​images.unsplash.com/​photo-1587502536575-6dfba0a6e017?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDF8MHxzZWFyY2h8MXx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")25driver.save_screenshot("beach1.png")26driver.get("https:/​/​images.unsplash.com/​photo-1507525428034-b723cf961d3e?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")27driver.save_screenshot("beach2.png")28driver.get("https:/​/​images.unsplash.com/​photo-1473116763249-2faaef81ccda?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")29driver.save_screenshot("beach3.png")30driver.get("https:/​/​images.unsplash.com/​photo-1520454974749-611b7248ffdb?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")31driver.save_screenshot("beach4.png")32driver.get("https:/​/​images.unsplash.com/​photo-1509233725247-49e657c54213?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")33driver.save_screenshot("beach5.png")34driver.get("https:/​/​images.unsplash.com/​photo-1471922694854-ff1b63b20054?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")35driver.save_screenshot("beach6.png")36driver.get("https:/​/​images.unsplash.com/​photo-1519046904884-53103b34b206?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")37driver.save_screenshot("beach7.png")38driver.get("https:/​/​images.unsplash.com/​photo-1564419320461-6870880221ad?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OHx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800&q=60")39driver.save_screenshot("beach8.png")40driver.get("https:/​/​images.unsplash.com/​photo-1506953823976-52e1fdc0149a?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8YmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=800")41driver.save_screenshot("beach9.png")42driver.get("https:/​/​images.unsplash.com/​photo-1559494007-9f5847c49d94?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTB8fGJlYWNofGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=800")43driver.save_screenshot("beach10.png")44driver.get("https:/​/​images.unsplash.com/​photo-1529778873920-4da4926a72c2?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")45driver.save_screenshot("animal1.png")46driver.get("https:/​/​images.unsplash.com/​photo-1574870111867-089730e5a72b?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")47driver.save_screenshot("animal2.png")48driver.get("https:/​/​images.unsplash.com/​photo-1591824438708-ce405f36ba3d?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")49driver.save_screenshot("animal3.png")50driver.get("https:/​/​images.unsplash.com/​photo-1564349683136-77e08dba1ef7?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")51driver.save_screenshot("animal4.png")52driver.get("https:/​/​images.unsplash.com/​photo-1583337130417-3346a1be7dee?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")53driver.save_screenshot("animal5.png")54driver.get("https:/​/​images.unsplash.com/​photo-1456926631375-92c8ce872def?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OHx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")55driver.save_screenshot("animal6.png")56driver.get("https:/​/​images.unsplash.com/​photo-1589656966895-2f33e7653819?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")57driver.save_screenshot("animal7.png")58driver.get("https:/​/​images.unsplash.com/​photo-1474511320723-9a56873867b5?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTB8fGFuaW1hbHN8ZW58MHx8MHx8&auto=format&fit=crop&w=800")59driver.save_screenshot("animal8.png")60driver.get("https:/​/​images.unsplash.com/​photo-1484406566174-9da000fda645?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")61driver.save_screenshot("animal9.png")62driver.get("https:/​/​images.unsplash.com/​photo-1574068468668-a05a11f871da?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YW5pbWFsc3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800")63driver.save_screenshot("animal10.png")...

Full Screen

Full Screen

base_page.py

Source: base_page.py Github

copy

Full Screen

...8class BasePage:9 """封装所有页面公共的非业务操作"""10 def __init__(self,driver):11 self.driver = driver12 def save_screenshot(self):13 """保存截图"""14 screenshot_time = time.strftime('%Y-%m-%d %H_%M_%S') #截图的时间15 file_name = screenshot_dir + '{0}.png'.format(screenshot_time) #截图保存的路径和名称16 try:17 self.driver.save_screenshot(file_name)18 MyLogger().info('截图成功,图片路径为{0}'.format(file_name))19 except:20 MyLogger().error('截图失败!')21 def wait_element_visible(self,locator,timeout=20):22 """等待元素可见"""23 MyLogger().info('等待{0}元素可见'.format(locator))24 try:25 WebDriverWait(self.driver,timeout).until(EC.visibility_of_element_located(locator))26 except:27 self.save_screenshot()28 MyLogger().error('等待元素可见失败!')29 raise30 def wait_element_present(self,locator,timeout=20):31 """等待元素存在"""32 MyLogger().info('等待{0}元素存在'.format(locator))33 try:34 WebDriverWait(self.driver,timeout).until(EC.presence_of_element_located(locator))35 except:36 self.save_screenshot()37 MyLogger().error('等待元素存在失败!')38 raise39 def get_element(self,locator):40 """查找元素"""41 MyLogger().info('查找元素:{0}'.format(locator))42 try:43 return self.driver.find_element(*locator)44 except:45 self.save_screenshot()46 MyLogger().error('查找元素失败!')47 raise48 def click_element(self,locator):49 """点击元素操作"""50 MyLogger().info('点击元素{0}'.format(locator))51 element = self.get_element(locator)52 try:53 element.click()54 except:55 self.save_screenshot()56 MyLogger().error('点击元素失败!')57 raise58 def input_text(self,locator,text):59 """输入文本操作"""60 MyLogger().info('元素{0}输入{1}'.format(locator,text))61 element = self.get_element(locator)62 try:63 element.send_keys(text)64 except:65 self.save_screenshot()66 MyLogger().error('输入文本失败!')67 raise68 def get_element_attribute(self,locator,attribute):69 """获取元素属性"""70 MyLogger().info('获取元素{0}的{1}属性'.format(locator,attribute))71 element = self.get_element(locator)72 try:73 return element.get_attribute(attribute)74 except:75 self.save_screenshot()76 MyLogger().error('获取元素属性失败!')77 raise78 def get_element_text(self,locator):79 """获取元素文本内容"""80 MyLogger().info('获取元素{0}的文本内容'.format(locator))81 element = self.get_element(locator)82 try:83 return element.text84 except:85 self.save_screenshot()86 MyLogger().error('获取元素文本内容失败!')87 raise88 def wait_alert_visible(self,timeout=20):89 """等待alert弹框出现"""90 MyLogger().info('等待alert弹框出现')91 try:92 WebDriverWait(self.driver,timeout).until(EC.alert_is_present())93 except:94 self.save_screenshot()95 MyLogger().error('等待alert弹框出现失败!')96 raise97 def alert_operation(self,operation='accept'):98 """alert处理操作,默认同意"""99 MyLogger().info('alert弹框处理')100 try:101 alert = self.driver.switch.to_alert102 if operation == 'accept':103 alert.accept()104 elif operation == 'dismiss':105 alert.dismiss()106 except:107 self.save_screenshot()108 MyLogger().error('alert弹框处理失败!')109 raise110 def switch_iframe(self,iframe_name,timeout=20):111 """iframe切换操作"""112 MyLogger().info('元素{0}操作iframe切换'.format(iframe_name))113 try:114 WebDriverWait(self.driver,timeout).until(EC.frame_to_be_available_and_switch_to_it(iframe_name))115 except:116 self.save_screenshot()117 MyLogger().error('iframe切换失败!')118 raise119 def scrollbar_operation(self):120 """滚动条处理--移动到页面底部"""121 MyLogger().info('将滚动条移动到页面底部')122 try:123 self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")124 except:125 self.save_screenshot()126 MyLogger().error('滚动条移动到页面底部失败!')...

Full Screen

Full Screen

save_screenshot.py

Source: save_screenshot.py Github

copy

Full Screen

1from screenplay import Task, Actor, log_message2from screenplay_selenium.actions import save_screenshot_to_file3from os import path4class save_screenshot(Task):5 path = None6 index = 07 def __init__(self):8 super().__init__()9 save_screenshot.index += 110 self._index = save_screenshot.index11 @log_message("Save screenshot '{self._index}.png'")12 def perform_as(self, actor: Actor):13 assert save_screenshot.path is not None, "capture_screenshot.path not set before trying to capture a screenshot"14 filename = path.join(save_screenshot.path, str(self._index) + '.png')15 actor.attempts_to(16 save_screenshot_to_file(filename)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Feeding your QA Career – Developing Instinctive & Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

A Complete Guide To CSS Grid

Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.

Keeping Quality Transparency Throughout the organization

In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.

A Detailed Guide To Xamarin Testing

Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.

How To Run Cypress Tests In Azure DevOps Pipeline

When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase 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