Giter VIP home page Giter VIP logo

selenium-ui-testing-with-aws-lambda-layers's Introduction

Selenium UI testing with AWS Lambda Layers

This is an example of set up Selenium testing with AWS lambda layers Python3.6

File Structure

  • seleniumLayer - Selenium
  • lambda
── /seleniumLayer/  # lambda layers
  ├── /selenium  lambda layer of selenium lib
  │  └──/python/      # python libs
  │   └── /lib/    
  │     └── /python3.6/*    
  ├── /chromedriver/    # lambda layer of headless Chrome 
  │ ├── /chromedriver   # chrome driver
  │ └── /headless-chromium # headless chrome binary
  └── /serverless.yaml     
── /lambda/            # lambda function
  ├── /handler.py      # source code of lambda function 
  └── /serverless.yaml # serverless config

Stack

Install

Go to root directory of project

# download Selenium 2.37
$ pip3.6 install -t seleniumLayer/selenium/python/lib/python3.6/site-packages selenium==2.37

# download chrome driver
$ cd seleniumLayer
$ mkdir chromedriver
$ cd chromedriver
$ curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > chromedriver.zip
$ unzip chromedriver.zip
$ rm chromedriver.zip

# download chrome binary
$ curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > headless-chromium.zip
$ unzip headless-chromium.zip
$ rm headless-chromium.zip

Install serverless command

Do this if you don't have serverless in your machine yet

npm config set prefix /usr/local
and then,
npm i -g serverless

Deploy Lambda Layers

Go to root directory of project

$ cd seleniumLayer
$ sls deploy 

Deploy Lambda Function

Go to root directory of project

$ cd lambda
$ sls deploy 

Start Testing

Go to root directory of project

$ cd lambda
$ sls invoke --function hello

selenium-ui-testing-with-aws-lambda-layers's People

Contributors

kumarcode avatar ricalanis avatar yai111 avatar yai333 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

selenium-ui-testing-with-aws-lambda-layers's Issues

No module named 'selenium.webdriver.chrome'

I followed the steps outlined in the README. However, I encountered the following error when I executed the Lambda:
Unable to import module 'handler': No module named 'selenium.webdriver.chrome'

chromedriver doesn't have permission to run

If I try and run it as you have laid out I get the following error.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

If I change
driver = webdriver.Chrome('/opt/chromedriver',chrome_options=options)
to
driver = webdriver.Chrome('/opt/chromedriver.exe',chrome_options=options) I get a new error

selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Configuration warning

In the deployment phase, i got a few warning logs like this:

Serverless: Configuration warning:
Serverless:   at 'layers.selenium': unrecognized property 'CompatibleRuntimes'
Serverless:   at 'layers.chromedriver': unrecognized property 'CompatibleRuntimes'
Serverless:  
Serverless: Learn more about configuration validation here: http://slss.io/configuration-validation

unknown error: unable to discover open pages

I keep encountering this error message when I try and run in AWS Lambda:

{
  "errorMessage": "Message: 'unknown error: unable to discover open pages\\n  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.165-102.205.amzn2.x86_64 x86_64)' ",
  "errorType": "WebDriverException",
  "stackTrace": [
    [
      "/var/task/src/lambda_function.py",
      35,
      "lambda_handler",
      "driver = webdriver.Chrome(chrome_options=chrome_options)"
    ],
    [
      "/var/task/lib/selenium/webdriver/chrome/webdriver.py",
      64,
      "__init__",
      "desired_capabilities=desired_capabilities)"
    ],
    [
      "/var/task/lib/selenium/webdriver/remote/webdriver.py",
      71,
      "__init__",
      "self.start_session(desired_capabilities, browser_profile)"
    ],
    [
      "/var/task/lib/selenium/webdriver/remote/webdriver.py",
      113,
      "start_session",
      "'desiredCapabilities': desired_capabilities,"
    ],
    [
      "/var/task/lib/selenium/webdriver/remote/webdriver.py",
      164,
      "execute",
      "self.error_handler.check_response(response)"
    ],
    [
      "/var/task/lib/selenium/webdriver/remote/errorhandler.py",
      164,
      "check_response",
      "raise exception_class(message, screen, stacktrace)"
    ]
  ]
}

I encounter this when using the version stack you have suggested: Python3.6, Selenium2.37, ChromeDriver2.37, Serverless Chrome v1.0.0-41.

I also encounter it when I use the version stack that has been discussed in this issue as being a compatible set of versions (Python3.6, Selenium3.14, ChromeDriver2.43, Serverless Chrome v1.0.0-55).

Some Googling has suggested that adding chrome_options.add_argument('--no-sandbox') is a fix but this has not worked for me.

Any suggestions?

How to change S3 bucket

Hi. Many thanks for sharing this. I'm struggling to change the S3 bucket from ServerlessDeploymentBucket. I've tried changing all references in lambda/.serverless/*.json files, but these are overwritten on sls deploy.

I've changed all references in the whole repo until search for ServerlessDeploymentBucket returns nothing, but they still come back! What am I missing?

ChromeDriver executable needs to be available in the path...

hey guys,
I'm new to AWS Lambda just getting all running if I use the dashs ... how can I create all stuffs that is inside READ.ME ? do I have to open the cli Cludshell ? There is nothing like you are showing to get the ChromeDriver work ... sorry the dumb question ... but I need a light ...

ChromeDriver executable needs to be available in the path

I followed all steps in the README. When I execute the lambda function,

serverless invoke --function hello

I get the error:

{
    "errorMessage": "Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://code.google.com/p/chromedriver/downloads/list                and read up at http://code.google.com/p/selenium/wiki/ChromeDriver' ",
    "errorType": "WebDriverException",
    "stackTrace": [
        [
            "/var/task/handler.py",
            13,
            "hello",
            "driver = webdriver.Chrome('/opt/chromedriver', chrome_options=options)"
        ],
        [
            "/opt/python/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py",
            59,
            "__init__",
            "self.service.start()"
        ],
        [
            "/opt/python/lib/python3.6/site-packages/selenium/webdriver/chrome/service.py",
            68,
            "start",
            "and read up at http://code.google.com/p/selenium/wiki/ChromeDriver\")"
        ]
    ]
}

I have checked in the deployment bucket in S3 and the chromedriver file is under s3://selenium-layer-dev-serverlessdeploymentbucket-10lxthu8funhm/serverless/selenium-layer/dev/1586419384780-2020-04-09T08:03:04.780Z/chromedriver.zip, as it should be.

What are I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.