Running Selenium
Abstra has a built-in Selenium environment that allows you to run your Selenium scripts in the cloud. Its URL is available in the ABSTRA_SELENIUM_URL
environment variable.
You may use the ABSTRA_ENVIRONMENT
environment variable to check if you are running in the cloud or locally and configure your Selenium driver accordingly.
import os
from selenium import webdriver
ABSTRA_ENVIRONMENT = os.getenv('ABSTRA_ENVIRONMENT')
ABSTRA_SELENIUM_URL = os.getenv('ABSTRA_SELENIUM_URL')
if ABSTRA_ENVIRONMENT=='production':
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
driver = webdriver.Remote(command_executor=ABSTRA_SELENIUM_URL, options=options)
else:
driver = webdriver.Chrome()
driver.get("https://abstra.io")
driver.save_screenshot("/tmp/screenshot.png")
driver.quit()