How to use add_meta_tag method in SeleniumBase

Best Python code snippet using SeleniumBase

parser.py

Source:parser.py Github

copy

Full Screen

...26 note_soup.name = 'div'27 note_soup['class'] = 'note'28 soup.body.append(note_soup)29 meta_tags = {}30 def add_meta_tag(name, content):31 meta_tags[name] = content32 new_tag = soup.new_tag('meta', content=content)33 new_tag['name'] = name34 soup.head.append(new_tag)35 add_meta_tag('slug', note_slug)36 add_meta_tag('category', note_info.notebook.name)37 add_meta_tag('date', format_timestamp(note.created))38 add_meta_tag('modified', format_timestamp(note.updated))39 path_map = {40 'notebook': notebook_slug,41 'note': note_slug42 }43 content_path = note_paths.content.format(**path_map)44 html_path = note_paths.html.format(**path_map)45 file_path = note_paths.file.format(**path_map)46 replace_media_tags(media_cache, soup, note, note_info.store, html_path, file_path, add_meta_tag)47 if note.attributes.latitude is not None and note.attributes.longitude is not None:48 place = note_info.get_place(note.attributes.latitude, note.attributes.longitude)49 if place:50 add_meta_tag('city', place)51 else:52 add_meta_tag('latitude', note.attributes.latitude)53 add_meta_tag('longitude', note.attributes.longitude)54 tags = linkify_soup(soup, soup.new_tag)55 add_meta_tag('tags', u', '.join(tags))56 summary = get_summary(note_soup, 120)57 add_meta_tag('summary', summary)58 # Facebook OG tags59 add_meta_tag('og:title', note.title)60 add_meta_tag('og:site_name', 'avalarky report')61 add_meta_tag('og:description', summary)62 add_meta_tag('og:type', 'article')63 if 'hero_image' in meta_tags:64 add_meta_tag('og:image', meta_tags['hero_image'])65 if not path.exists(content_path):66 os.makedirs(content_path, mode=0755)67 with open(path.join(content_path, 'index.html'), 'w') as f:68 f.write(soup.prettify().encode('utf-8'))69def get_summary(soup, summary_length):70 word_list = soup.get_text(separator=u' ').strip().replace(u'\n', u'—').split()71 summary = ''72 while len(summary) < summary_length and len(word_list) > 0:73 summary += ' ' + word_list.pop(0)74 return summary.strip()75def replace_media_tags(media_cache, soup, note, note_store, html_path, file_path, add_meta_tag):76 all_media = soup.find_all('en-media')77 if not len(all_media) > 0 and not path.exists(file_path):78 os.makedirs(file_path, mode=0755)79 # TODO: pending settings refactor80 scaled_size = (400, 400)81 hero_size = (800, 300)82 thumbnail_size = (200, 200)83 for i, media in enumerate(all_media):84 resource_hash = media['hash']85 ext = MIME_TO_EXTESION_MAPPING[media['type']]86 full_filename = '{}{}'.format(resource_hash, ext)87 scaled_filename = '{}-{}x{}{}'.format(resource_hash, scaled_size[0], scaled_size[1], ext)88 outputs = [89 (path.join(file_path, full_filename), None, None),90 (path.join(file_path, scaled_filename), scaled_size, constrain_size),91 ]92 if i == 0:93 thumbnail_filename = 'thumbnail{}'.format(ext)94 hero_filename = 'hero{}'.format(ext)95 outputs += [96 (path.join(file_path, thumbnail_filename), thumbnail_size, scale_and_crop),97 (path.join(file_path, hero_filename), hero_size, scale_and_crop)98 ]99 add_meta_tag('hero_image', path.join(html_path, hero_filename))100 add_meta_tag('thumbnail_image', path.join(html_path, thumbnail_filename))101 save_media(media_cache, resource_hash, note_store, note.guid, outputs)102 anchor = soup.new_tag('a', href=path.join(html_path, full_filename), target='_blank')103 img = soup.new_tag('img', src=path.join(html_path, scaled_filename))104 anchor.append(img)105 media.replace_with(anchor)106def save_media(media_cache, resource_hash, note_store, note_guid, outputs):107 new_outputs = [output for output in outputs if not path.exists(output[0])]108 if len(new_outputs) == 0:109 return110 log.info('Resource {} has new outputs'.format(resource_hash))111 data = media_cache.load(resource_hash)112 if not data:113 data = get_resource_by_hash(note_store, note_guid, resource_hash)114 log.info('Retrieved resource')...

Full Screen

Full Screen

test_snare_helpers_add_meta_tag.py

Source:test_snare_helpers_add_meta_tag.py Github

copy

Full Screen

...13 self.page_dir = self.main_page_path.rsplit('/')[-1]14 self.index_page = "index.html"15 with open(os.path.join(self.main_page_path, 'index.html'), 'w') as f:16 f.write(self.content)17 def test_add_meta_tag(self):18 config = configparser.ConfigParser()19 config['WEB-TOOLS'] = dict(google='test google content',20 bing='test bing content')21 add_meta_tag(self.page_dir, self.index_page, config)22 with open(os.path.join(self.main_page_path, 'index.html')) as main:23 main_page = main.read()24 soup = BeautifulSoup(main_page, 'html.parser')25 assert(soup.find("meta",26 attrs={"name": "google-site-verification"}) and soup.find("meta",27 attrs={"name": "msvalidate.01"}))28 def test_add_meta_tag_with_empty_tags(self):29 config = configparser.ConfigParser()30 config['WEB-TOOLS'] = dict(google='', bing='')31 assert add_meta_tag(self.page_dir, self.index_page, config) is None32 def tearDown(self):...

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