changed locators a bit & updated chunks generator

pull/963/head
Drugsosos 2 years ago
parent 1931b5e8e5
commit 9c81447096
No known key found for this signature in database
GPG Key ID: 8E35176FE617E28D

@ -66,7 +66,19 @@ def catch_exception(
# Lots of tabs - lots of memory # Lots of tabs - lots of memory
# chunk needed to minimize memory required # chunk needed to minimize memory required
def chunks(lst, n): def chunks(
"""Yield successive n-sized chunks from list.""" array: list,
for i in range(0, len(lst), n): size: int,
yield lst[i:i + n] ):
"""
Yield successive n-sized chunks from list.
Args:
array: List to be chunked
size: size of a chunk
Returns:
Generator with chunked list
"""
for i in range(0, len(array), size):
yield array[i:i + size]

@ -14,7 +14,6 @@ from utils.console import print_step, print_substep
import webdriver.common as common import webdriver.common as common
common.default_exception = TimeoutError common.default_exception = TimeoutError
@ -188,7 +187,7 @@ class RedditScreenshot(Flaky, Browser):
# Triggers indirectly reload # Triggers indirectly reload
await self.click( await self.click(
page_instance, page_instance,
'button:has-text("Yes")', "button:has-text('Yes')",
{"timeout": 5000}, {"timeout": 5000},
) )
@ -197,7 +196,7 @@ class RedditScreenshot(Flaky, Browser):
await self.click( await self.click(
page_instance, page_instance,
'button:has-text("Click to see nsfw")', "button:has-text('Click to see nsfw')",
{"timeout": 5000}, {"timeout": 5000},
) )
@ -229,7 +228,7 @@ class RedditScreenshot(Flaky, Browser):
await self.screenshot( await self.screenshot(
comment_page, comment_page,
f"[data-testid='post-container']", f"id=t1_{comment_obj['comment_id']}",
{"path": f"assets/temp/png/comment_{filename_idx}.png"}, {"path": f"assets/temp/png/comment_{filename_idx}.png"},
) )
@ -246,20 +245,23 @@ class RedditScreenshot(Flaky, Browser):
) )
split_story_tl = story_tl.split('\n') split_story_tl = story_tl.split('\n')
await main_page.evaluate( await main_page.evaluate(
# Find all elements # Find all elements with story text
'var elements = document.querySelectorAll(`[data-test-id="post-content"]' "const elements = document.querySelectorAll('[data-test-id=\"post-content\"]"
' > [data-click-id="text"] > div > p`);' " > [data-click-id=\"text\"] > div > p');"
# Set array with translated text # Set array with translated text
f"var texts = {split_story_tl};" f"const texts = {split_story_tl};"
# Map 2 arrays together # Map 2 arrays together
"var text_map = texts.map(function(e, i) { return [e, elements[i]]; });" "const concat = (element, i) => [element, elements[i]];"
"const mappedTexts = texts.map(concat);"
# Change text on the page # Change text on the page
"for (i = 0; i < text_map.length; ++i) { text_map[i][1].textContent = text_map[i][0] ; };" "for (i = 0; i < mappedTexts.length; ++i) {"
"mappedTexts[i][1].textContent = mappedTexts[i][0];"
"};"
) )
await self.screenshot( await self.screenshot(
main_page, main_page,
'[data-test-id="post-content"] > [data-click-id="text"]', "data-test-id='post-content' > data-click-id='text'",
{"path": "assets/temp/png/story_content.png"}, {"path": "assets/temp/png/story_content.png"},
) )

@ -18,7 +18,6 @@ from typing import Optional
import webdriver.common as common import webdriver.common as common
common.default_exception = BrowserTimeoutError common.default_exception = BrowserTimeoutError
@ -183,27 +182,27 @@ class RedditScreenshot(Browser, Wait):
await self.click( await self.click(
page_instance, page_instance,
"//*[contains(@class, 'header-user-dropdown')]", "//div[@class='header-user-dropdown']",
find_options={"timeout": 5000}, find_options={"timeout": 5000},
) )
# It's normal not to find it, sometimes there is none :shrug: # It's normal not to find it, sometimes there is none :shrug:
await self.click( await self.click(
page_instance, page_instance,
"//*[contains(text(), 'Settings')]/ancestor::button[1]", "//span[text()='Settings']/ancestor::button[1]",
find_options={"timeout": 5000}, find_options={"timeout": 5000},
) )
await self.click( await self.click(
page_instance, page_instance,
"//*[contains(text(), 'Dark Mode')]/ancestor::button[1]", "//span[text()='Dark Mode']/ancestor::button[1]",
find_options={"timeout": 5000}, find_options={"timeout": 5000},
) )
# Closes settings # Closes settings
await self.click( await self.click(
page_instance, page_instance,
"//*[contains(@class, 'header-user-dropdown')]", "//div[@class='header-user-dropdown']",
find_options={"timeout": 5000}, find_options={"timeout": 5000},
) )
@ -268,7 +267,7 @@ class RedditScreenshot(Browser, Wait):
await self.screenshot( await self.screenshot(
comment_page, comment_page,
f"//*[contains(@id, 't1_{comment_obj['comment_id']}')]", f"//div[@id='t1_{comment_obj['comment_id']}']",
{"path": f"assets/temp/png/comment_{filename_idx}.png"}, {"path": f"assets/temp/png/comment_{filename_idx}.png"},
) )
@ -285,15 +284,18 @@ class RedditScreenshot(Browser, Wait):
) )
split_story_tl = story_tl.split('\n') split_story_tl = story_tl.split('\n')
await main_page.evaluate( await main_page.evaluate(
# Find all elements # Find all elements with story text
'var elements = document.querySelectorAll(`[data-test-id="post-content"]' "const elements = document.querySelectorAll('[data-test-id=\"post-content\"]"
' > [data-click-id="text"] > div > p`);' " > [data-click-id=\"text\"] > div > p');"
# Set array with translated text # Set array with translated text
f"var texts = {split_story_tl};" f"const texts = {split_story_tl};"
# Map 2 arrays together # Map 2 arrays together
"var text_map = texts.map(function(e, i) { return [e, elements[i]]; });" "const concat = (element, i) => [element, elements[i]];"
"const mappedTexts = texts.map(concat);"
# Change text on the page # Change text on the page
"for (i = 0; i < text_map.length; ++i) { text_map[i][1].textContent = text_map[i][0] ; };" "for (i = 0; i < mappedTexts.length; ++i) {"
"mappedTexts[i][1].textContent = mappedTexts[i][0];"
"};"
) )
await self.screenshot( await self.screenshot(
@ -359,7 +361,7 @@ class RedditScreenshot(Browser, Wait):
async_tasks_primary.append( async_tasks_primary.append(
self.screenshot( self.screenshot(
reddit_main, reddit_main,
f'//*[@data-testid="post-container"]', f"//div[@data-testid='post-container']",
{"path": "assets/temp/png/title.png"}, {"path": "assets/temp/png/title.png"},
) )
) )

Loading…
Cancel
Save