by Lazy Sloth
Selenium App
import logging
import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from selenium_utils import SeleniumUtility
URL_TO_FETCH = "https://www.example.com"
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def page_information():
selenium_util = SeleniumUtility()
title = (
selenium_util.get_page_title(URL_TO_FETCH) or "Failed to retrieve page title"
)
return templates.TemplateResponse("page_information.html", {"page_title": title})
Selenium App
Created: | Last Updated:
Introduction to the Selenium App Template
Welcome to the step-by-step guide on how to use the Selenium App template on Lazy. This template is designed for builders who need to automate web interactions such as end-to-end tests, functional tests, or web crawling with sophisticated steps like clicks and element interactions. By the end of this guide, you'll be able to deploy an app that uses Selenium to fetch and display the title of a web page.
Getting Started
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.
Test: Deploying the App
Once you've started with the template, press the "Test" button. This will initiate the deployment of your app and launch the Lazy CLI. The deployment process is handled entirely by Lazy, so you don't need to worry about installing libraries or setting up your environment.
Using the App
After the app is deployed, Lazy will provide you with a dedicated server link. You can use this link to interact with your Selenium App. If you're using FastAPI, Lazy will also provide a docs link, which you can use to explore the API endpoints and their functionalities.
The main endpoint of your app will be the root ("/"), which, when accessed, will use Selenium to fetch the title of the specified URL and display it in a simple HTML page. Here's what the HTML page will look like:
`<!DOCTYPE html>
Page Title
{{ page_title }}