This commit is contained in:
Josh at WLTechBlog
2025-08-18 11:00:16 -05:00
parent e5f998e005
commit 4ea5615ef8
7 changed files with 422 additions and 27 deletions

27
main.go
View File

@@ -216,14 +216,29 @@ func main() {
// Create a client
c := client.NewClient(*uploadFileHost, *uploadFilePort)
// Upload the file
err := c.UploadFile(*uploadFileTabID, *uploadFileSelector, *uploadFilePath, *uploadFileSelectionTimeout, *uploadFileActionTimeout)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
// Check if the local file exists
if _, err := os.Stat(*uploadFilePath); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error: Local file does not exist: %s\n", *uploadFilePath)
os.Exit(1)
}
fmt.Println("File uploaded successfully")
// First, transfer the file to the daemon container
fmt.Printf("Transferring file to daemon container: %s\n", *uploadFilePath)
containerPath, err := c.UploadFileToContainer(*uploadFilePath, "")
if err != nil {
fmt.Fprintf(os.Stderr, "Error transferring file to container: %v\n", err)
os.Exit(1)
}
fmt.Printf("File transferred to container: %s\n", containerPath)
// Then upload the file to the web form using the container path
err = c.UploadFile(*uploadFileTabID, *uploadFileSelector, containerPath, *uploadFileSelectionTimeout, *uploadFileActionTimeout)
if err != nil {
fmt.Fprintf(os.Stderr, "Error uploading file to web form: %v\n", err)
os.Exit(1)
}
fmt.Println("File uploaded to web form successfully")
case "submit-form":
submitFormCmd.Parse(os.Args[2:])
@@ -475,7 +490,7 @@ func printUsage() {
fmt.Println(" open-tab Open a new tab and return its ID")
fmt.Println(" load-url Load a URL in a tab")
fmt.Println(" fill-form Fill a form field with a value")
fmt.Println(" upload-file Upload a file to a file input")
fmt.Println(" upload-file Transfer a file to daemon container and upload to a file input")
fmt.Println(" submit-form Submit a form")
fmt.Println(" get-source Get the source code of a page")
fmt.Println(" get-element Get the HTML of an element")