Selenium WebDriver

SSL Certificate & File Upload Handling

Learn to handle SSL certificates and automate file uploads using AutoIT library in Selenium WebDriver.

SSL Certificate Handling in Selenium

Understanding SSL Certificates

SSL (Secure Socket Layers) certificates provide encryption and security for web communications. In testing environments, self-signed certificates often cause browser security warnings.

SSL Certificate Types

  • • Production: Valid SSL certificates
  • • QA/UAT: Self-signed certificates
  • • Development: Local certificates
  • • Testing: Temporary certificates

Common SSL Issues

  • • "Your connection is not private"
  • • "This site is not secure"
  • • Certificate validation errors
  • • Selenium script failures

SSL Certificate Solution

4-Step SSL Handling Process

Step 1: Create ChromeOptions
ChromeOptions opt = new ChromeOptions();
Step 2: Accept Insecure Certs
opt.setAcceptInsecureCerts(true);
Step 3: Create Driver
ChromeDriver driver = new ChromeDriver(opt);
Step 4: Navigate to URL
driver.get("https://self-signed.badssl.com/");
package Tutorial20;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Demo1 {
    public static void main(String[] args) {

        // Step 1: Create ChromeOptions object
        ChromeOptions opt = new ChromeOptions();

        // Step 2: Accept insecure SSL certificates
        opt.setAcceptInsecureCerts(true);

        // Step 3: Create ChromeDriver with options
        ChromeDriver driver = new ChromeDriver(opt);

        // Step 4: Navigate to SSL protected site
        driver.get("https://self-signed.badssl.com/");

        driver.quit();
    }
}

File Upload Using AutoIT

Why AutoIT for File Upload?

Selenium cannot directly interact with Windows file dialogs. AutoIT library provides desktop automation capabilities to handle file upload dialogs that appear when clicking file input elements.

AutoIT Key Functions

  • • ControlFocus: Focus on dialog elements
  • • ControlSetText: Enter file path
  • • ControlClick: Click dialog buttons
  • • Sleep: Add delays between actions

Control Parameters

  • • Title: Dialog window title
  • • Text: Dialog text content
  • • ControlID: Element identifier
  • • Path: File location path

AutoIT Script Creation Process

7-Step AutoIT Implementation

Step 1: Open AutoIT Script Editor
Launch AutoIT SciTE Script Editor
Step 2: Focus on File Name Text Box
ControlFocus("Open", "", "Edit1")
Step 3: Enter File Path
ControlSetText("Open", "", "Edit1", "file_path")
Step 4: Click Open Button
ControlClick("Open", "", "Button1")
Step 5: Compile Script
Tools → Compile to generate .exe file
Step 6: Selenium Integration
Click file input to open dialog
Step 7: Execute AutoIT Script
Runtime.getRuntime().exec("script.exe")
; AutoIT Script for File Upload

; Step 1: Focus on File Name text box
ControlFocus("Open", "", "Edit1")
Sleep(2000)

; Step 2: Enter file path in text box
ControlSetText("Open", "", "Edit1", "C:\\Users\\praf0\\OneDrive\\Desktop\\Soft-Tech Classes, Pune.xlsx")
Sleep(2000)

; Step 3: Click Open button
ControlClick("Open", "", "Button1")
Sleep(2000)

File Upload Implementation Examples

Example 1: DemoQA File Upload

URL: https://demoqa.com/upload-download

Task: Upload Excel file using AutoIT automation

package Tutorial20;

import java.io.IOException;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class Demo2 {
    public static void main(String[] args) throws IOException, InterruptedException {

        ChromeDriver driver = new ChromeDriver();
        driver.manage().window().maximize();

        driver.get("https://demoqa.com/upload-download");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

        // Locate file input element
        WebElement wb = driver.findElement(By.xpath("//label[text()='Select a file']/following-sibling::input"));
        Actions act = new Actions(driver);
        act.click(wb).build().perform();

        Thread.sleep(3000);

        // Execute AutoIT script for file upload
        Runtime.getRuntime().exec("C:\\\\Users\\\\praf0\\\\OneDrive\\\\Desktop\\\\Upload File folder\\\\UploadDocuments.exe");

        driver.quit();
    }
}

Example 2: Automation Testing File Upload

URL: https://demo.automationtesting.in/FileUpload.html

Task: Upload image file using AutoIT automation

package Tutorial20;

import java.io.IOException;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class Demo3 {
    public static void main(String[] args) throws InterruptedException, IOException {

        ChromeDriver driver = new ChromeDriver();
        driver.get("https://demo.automationtesting.in/FileUpload.html");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));

        // Locate file input element
        WebElement wb = driver.findElement(By.id("input-4"));
        Actions act = new Actions(driver);
        act.click(wb).build().perform();

        Thread.sleep(4000);

        // Execute AutoIT script for image upload
        Runtime.getRuntime().exec("C:\\\\Users\\\\praf0\\\\OneDrive\\\\Desktop\\\\Upload File folder\\\\UploadImage.exe");

        driver.quit();
    }
}
; AutoIT Script for Image Upload (UploadImage.exe)

ControlFocus("Open", "", "Edit1")

ControlSetText("Open", "", "Edit1", "C:\\Users\\praf0\\OneDrive\\Pictures\\Screenshots\\Screenshot 2023-11-23 111341.png")

ControlClick("Open", "", "Button1")

Best Practices & Tips

✅ SSL Certificate Best Practices

  • • Use setAcceptInsecureCerts(true) for testing
  • • Only for QA/UAT environments
  • • Never use in production testing
  • • Document SSL handling in test cases
  • • Test with valid certificates when possible

🔧 AutoIT Implementation Tips

  • • Create separate AutoIT scripts for different file types
  • • Use absolute file paths in AutoIT scripts
  • • Add Sleep() delays between AutoIT actions
  • • Test AutoIT scripts independently first
  • • Keep AutoIT .exe files in project resources

❌ Common Mistakes

  • • Not handling SSL certificates in test environments
  • • Using incorrect AutoIT control IDs
  • • Missing Thread.sleep() before AutoIT execution
  • • Hardcoding file paths in AutoIT scripts
  • • Not compiling AutoIT scripts to .exe

⚠️ Important Notes

  • • AutoIT works only on Windows OS
  • • File dialog titles may vary by browser
  • • Control IDs might change with OS updates
  • • Always verify file upload success

Knowledge Check

Knowledge Check

Question 1 of 5

What does SSL stand for in web security?

Key Takeaways

🔒 SSL Certificate Handling

  • • SSL provides web security encryption
  • • Self-signed certificates cause browser warnings
  • • Use setAcceptInsecureCerts(true) for testing
  • • ChromeOptions required for SSL configuration

📁 File Upload Automation

  • • AutoIT handles Windows file dialogs
  • • ControlFocus → ControlSetText → ControlClick
  • • Compile AutoIT scripts to .exe files
  • • Execute using Runtime.getRuntime().exec()

⚡ Implementation Strategy

  • • Test SSL handling in QA environments
  • • Create reusable AutoIT scripts
  • • Add appropriate delays for dialog handling
  • • Verify upload success after automation

🎯 Remember

  • • SSL handling only for test environments
  • • AutoIT is Windows-specific solution
  • • Always test AutoIT scripts independently
  • • Use absolute paths in file operations

SDET Mastery

Master Test Automation

Home
CurriculumPracticeQ&ACheatsheet
🍵Buy me a Chai

Automation Testing Course

Comprehensive course covering Manual Testing, Java Programming, and Selenium WebDriver

🍵Buy me a Chai
Privacy Policy•GitHub
© 2024 Automation Testing Course. All rights reserved.