How to use screenshot_as_base64 method in Selene

Best Python code snippet using selene_python

screenshot.py

Source:screenshot.py Github

copy

Full Screen

...101 raise RuntimeError("Failed to save screenshot '{}'.".format(path))102 self._embed_to_log_as_file(path, 800)103 return path104 def _capture_page_screen_to_log(self):105 screenshot_as_base64 = self.driver.get_screenshot_as_base64()106 self._embed_to_log_as_base64(screenshot_as_base64, 800)107 return EMBED108 @keyword109 def capture_element_screenshot(self, locator, filename=DEFAULT_FILENAME_ELEMENT):110 """Captures a screenshot from the element identified by ``locator`` and embeds it into log file.111 See `Capture Page Screenshot` for details about ``filename`` argument.112 See the `Locating elements` section for details about the locator113 syntax.114 An absolute path to the created element screenshot is returned.115 Support for capturing the screenshot from an element has limited support116 among browser vendors. Please check the browser vendor driver documentation117 does the browser support capturing a screenshot from an element.118 New in SeleniumLibrary 3.3. Support for EMBED is new in SeleniumLibrary 4.2.119 Examples:...

Full Screen

Full Screen

check_snowbird.py

Source:check_snowbird.py Github

copy

Full Screen

1"""2This file checks the snowbird reservation website for available dates.3If one of the dates that we want is available, sent a notification through email or text4Author: Michael Ershov5Date: 12/13/206"""7#---------------------------------------------------------#8# IMPORT TIME #9#---------------------------------------------------------#10import time11from bs4 import BeautifulSoup12from bs4 import SoupStrainer13from selenium import webdriver14from selenium.webdriver.common.keys import Keys15import requests16import numpy as np17import pickle18import sys19import copy20from urllib.request import urlopen21import base6422import io23from PIL import Image24import os25from twilio.rest import Client26from playsound import playsound27import vlc28#---------------------------------------------------------#29# USED FUNCTIONS #30#---------------------------------------------------------#31def setup_driver(op_headless = False):32 chrome_options = webdriver.chrome.options.Options()33 if op_headless:34 chrome_options.add_argument("--headless")35 fnc_driver = webdriver.Chrome(options=chrome_options)36 return fnc_driver37def get_soup(fnc_url_link, soupit = False):38 driver.get(fnc_url_link)39 if soupit:40 soup_to_return = BeautifulSoup(driver.page_source, 'lxml')41 return soup_to_return42def save_str_img(inputStr, file_loc):43 img = Image.open(io.BytesIO(inputStr))44 rgb_im = img.convert('RGB')45 rgb_im.save(file_loc + '.jpg')46def play_alarm(alarm_time=20):47 file = 'annoying_alarm.mp3'48 print('Playing alarm...')49 p = vlc.MediaPlayer(file)50 p.play()51 currTime = time.time()52 # Play for 20 seconds53 while time.time() < currTime + alarm_time:54 pass55 p.stop()56# def send_text_msg(message_text):57# # Your Account Sid and Auth Token from twilio.com/console58# # and set the environment variables. See http://twil.io/secure59# account_sid = os.environ['AC7247fb44eb62d277a2d81dde0053b4c1']60# auth_token = os.environ['642432a674cf8eb3de0366aa72f0a1c4']61# client = Client(account_sid, auth_token)62#63# message = client.messages \64# .create(65# body=message_text,66# from_='+18583827358',67# to='+18583827358'68# )69#---------------------------------------------------------#70# MAIN FUNCTION #71#---------------------------------------------------------#72# Do not use main sentinal so that global variables can be used...73# We will not be using this file for imports anyway74snowbird_link = 'https://www.snowbird.com/parking/#parking_reservation'75# Setup the webdriver76driver = setup_driver(False)77# Get XML soup from the link78get_soup(snowbird_link)79time.sleep(0.5)80iframe_id = 'parking-widget'81driver.switch_to.frame(iframe_id)82# Grab all of the relevant dates83dec_18 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[3]/td[6]')84dec_19 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[3]/td[7]')85dec_20 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[1]')86dec_21 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[2]')87dec_22 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[3]')88prev_img_18 = dec_18.screenshot_as_base6489prev_img_19 = dec_19.screenshot_as_base6490prev_img_20 = dec_20.screenshot_as_base6491prev_img_21 = dec_21.screenshot_as_base6492prev_img_22 = dec_22.screenshot_as_base6493# # FOR DEBUGGING:94prev_img_20 = 'hello 1'95counter = 096while(True):97 # Grab webpgage (refresh it)98 get_soup(snowbird_link)99 time.sleep(3)100 iframe_id = 'parking-widget'101 driver.switch_to.frame(iframe_id)102 # Get all of the specific days103 dec_18 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[3]/td[6]')104 dec_19 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[3]/td[7]')105 dec_20 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[1]')106 dec_21 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[2]')107 dec_22 = driver.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div[2]/div/table/tbody/tr[4]/td[3]')108 # Get images of specific days109 curr_img_18 = dec_18.screenshot_as_base64110 curr_img_19 = dec_19.screenshot_as_base64111 curr_img_20 = dec_20.screenshot_as_base64112 curr_img_21 = dec_21.screenshot_as_base64113 curr_img_22 = dec_22.screenshot_as_base64114 # Now run comparisons115 if counter == 0:116 playTime = 10117 else:118 playTime = 100119 if curr_img_18 != prev_img_18:120 play_alarm(alarm_time = playTime)121 print('Day has changed! 18')122 if curr_img_19 != prev_img_19:123 play_alarm(alarm_time = playTime)124 print('Day has changed! 19')125 if curr_img_20 != prev_img_20:126 play_alarm(alarm_time = playTime)127 print('Day has changed! 20')128 if curr_img_21 != prev_img_21:129 play_alarm(alarm_time = playTime)130 print('Day has changed! 21')131 if curr_img_22 != prev_img_22:132 play_alarm(alarm_time = playTime)133 print('Day has changed! 22')134 # Set the previous days to be the current days for comparison135 prev_img_18 = curr_img_18136 prev_img_19 = curr_img_19137 prev_img_20 = curr_img_20138 prev_img_21 = curr_img_21139 prev_img_22 = curr_img_22140 print('Counter is at {0}'.format(counter))141 counter += 1142# a = soup.select('#parking_reservation')143# for i,elem in enumerate(a[0].children):144# if i == 1:145# nextElement = elem146# break147#148# for i,elem in enumerate(nextElement.children):...

Full Screen

Full Screen

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 Selene 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