Skip to content

Commit ed65319

Browse files
committed
testing actions
1 parent ab6aba2 commit ed65319

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

.github/scripts/take_screenshot.py

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ def setup_driver():
1212
print("Setting up Chrome driver...")
1313
chrome_options = Options()
1414

15-
# Required arguments for running in GitHub Actions
16-
chrome_options.add_argument('--headless=new') # Updated headless argument
15+
chrome_options.add_argument('--headless=new')
1716
chrome_options.add_argument('--no-sandbox')
1817
chrome_options.add_argument('--disable-dev-shm-usage')
19-
chrome_options.add_argument('--disable-gpu')
2018
chrome_options.add_argument('--window-size=1920,1080')
21-
chrome_options.add_argument('--disable-extensions')
22-
23-
# Additional debugging options
24-
chrome_options.add_argument('--verbose')
25-
chrome_options.add_argument('--log-level=0')
2619

2720
print("Chrome options configured, initializing driver...")
2821

@@ -36,64 +29,57 @@ def setup_driver():
3629
raise
3730

3831

39-
def take_element_screenshot(driver, url, selector, output_name):
32+
def take_screenshot(driver, url, cookie_value, selector, output_name):
4033
print(f"Attempting to take screenshot of {selector} at {url}")
4134
os.makedirs('screenshots', exist_ok=True)
4235

4336
try:
44-
print("Navigating to page...")
45-
driver.get(url)
37+
# First navigate to the domain to set cookie
38+
driver.get("https://adventofcode.com")
4639

47-
# Add a small delay to ensure page loads
48-
time.sleep(5)
49-
print("Page loaded, waiting for element...")
40+
# Set the session cookie
41+
driver.add_cookie({
42+
'name' : 'session',
43+
'value' : cookie_value,
44+
'domain': '.adventofcode.com'
45+
})
46+
47+
print("Cookie set, navigating to target page...")
48+
driver.get(url)
49+
time.sleep(3) # Allow page to load
5050

51-
# Wait for element to be present and visible
52-
element = WebDriverWait(driver, 20).until(
51+
print("Waiting for element...")
52+
element = WebDriverWait(driver, 10).until(
5353
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
5454
)
5555

56-
print("Element found, preparing for screenshot...")
57-
58-
# Ensure element is visible in viewport
59-
driver.execute_script("arguments[0].scrollIntoView();", element)
60-
time.sleep(2) # Give time for any animations to complete
61-
62-
# Take full page screenshot first for debugging
63-
driver.save_screenshot('screenshots/full_page.png')
64-
print("Full page screenshot saved for debugging")
65-
66-
# Take screenshot of specific element
56+
print("Element found, taking screenshot...")
6757
element.screenshot(f'screenshots/{output_name}.png')
68-
print(f"Element screenshot saved as screenshots/{output_name}.png")
58+
print(f"Screenshot saved as screenshots/{output_name}.png")
6959

7060
except Exception as e:
7161
print(f"Error during screenshot process: {str(e)}")
7262
print(f"Current URL: {driver.current_url}")
73-
print(f"Page source length: {len(driver.page_source)}")
7463
raise
7564

7665

7766
def main():
7867
print("Starting screenshot process...")
7968
driver = None
80-
try:
81-
driver = setup_driver()
8269

83-
# Test with a simple, reliable page first
84-
take_element_screenshot(
85-
driver=driver,
86-
url='https://example.com', # Using example.com as a test
87-
selector='h1', # Example.com has a simple h1 element
88-
output_name='test-screenshot'
89-
)
70+
# Get cookie from environment variable
71+
cookie = os.getenv('COOKIE')
72+
if not cookie:
73+
raise ValueError("COOKIE environment variable not set")
9074

91-
# If the above works, try your actual target
92-
take_element_screenshot(
75+
try:
76+
driver = setup_driver()
77+
take_screenshot(
9378
driver=driver,
94-
url='https://github.com',
95-
selector='.header',
96-
output_name='github-header'
79+
url='https://adventofcode.com/2024',
80+
cookie_value=cookie,
81+
selector='body > main > pre',
82+
output_name='aoc-content'
9783
)
9884

9985
except Exception as e:

0 commit comments

Comments
 (0)