Upload file to a S3 bucket using Python and Selenium automation testing framework

Today we will learn on how to upload a file to a S3 bucket using Selenium automation testing framework with python
Scenario: When you run the python script for selenium, the following steps will be executed:
      • A web browser will open and at the background a test file will be uploaded to S3
      • Web browser will then navigate to Amazon account > S3 bucket
      • Web browser will verify whether the file has been uploaded or not
Steps:
  • Login to your AWS account and go to S3

  • Create an empty S3 bucket
  • Install boto3 library for python
    • you can use either commands in terminal:
      • pip install boto3
      • easy_install boto3
  • Now create a selenium framework script using python
    • Import the boto3 library in the script
    • Specify your client key and secret key
    • Specify local file path
    • Specify a S3 file name that you want to give to this new file when uploaded in S3
  • Create a boto3 client object:
    • s3 = boto3.client('s3',aws_access_key_id=ACCESS_KEY, aws_secret_access_key_id=SECRET_KEY))
  • Use the below function to upload the file to S3:
    • s3.upload_file(local_file_path, bucket, s3_file_name_to_overwrite)
  • Run the script
  • After running the script, go to AWS S3 bucket and you will find the new file uploaded.
  • You are done :)
Note: the script shared above is only for uploading the file in S3, you have to add additional steps in the python selenium framework (after the upload code) to verify, whether, the file has been successfully uploaded in S3 or not.

Comments