Selenium automation on docker (Linux) not keep cacheStorage - docker

I run an automatin scenario Login into a website (Google IAP Login). I need to cache the cookies and storage so that on next automation no need to do Google IAP Login.
This automation run on docker, OS: Ubuntu.
Docker:
CHROME_ARGS="--disable-gpu --headless --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --user-data-dir=/chromedata --disable-dev-shm-usage --window-size=1366,768"
Selenium config:
Capybara.register_driver :docker do |app|
chrome_opts = Selenium::WebDriver::Chrome::Options.new
chrome_opts.add_argument("--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36"")
chrome_opts.add_argument('--headless')
chrome_opts.add_argument('--remote-debugging-port=9222')
chrome_opts.add_argument('--remote-debugging-address=0.0.0.0')
chrome_opts.add_argument('--no-first-run')
chrome_opts.add_argument('--disable-web-security')
chrome_opts.add_argument('--enable-automation')
chrome_opts.add_argument("--user-data-dir=/path/to/folder")
client = Selenium::WebDriver::Remote::Http::Default.new
client.open_timeout = wait_time
client.read_timeout = wait_time
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: chrome_opts,
http_client: client
)
end
chrome://version
After I execute the automation, and use the generated user profile. I still redirect to Google IAP Login (I assume that some cache not saved correctly, because the are no ../Service Worker/CacheStorage on profile folder)
Note: This docker and the generated profile data works when I did scenario login manually

Related

Invoke Lambda docker container locally by passing API Gateway like event object

I am trying out the newly added container image support for AWS Lambda service.
I have built a custom image using python-alpine as the base image. I have used the same Dockerfile mentioned in the article above. I am also able to invoke it using below command :
curl -v -X POST http://localhost:9000/2015-03-31/functions/function/invocations -H 'Content-Type: application/json' -d '{}'
This part -d '{}' is actually what is passed as the event. When this function is behind an actual AWS API gateway it gets the below event
{"resource":"/","path":"/view","httpMethod":"POST","headers":{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-GB,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4","cache-control":"max-age=0","CloudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile-Viewer":"false","CloudFront-Is-SmartTV-Viewer":"false","CloudFront-Is-Tablet-Viewer":"false","CloudFront-Viewer-Country":"GB","content-type":"application/x-www-form-urlencoded","Host":"j3ap25j034.execute-api.eu-west-2.amazonaws.com","origin":"https://j3ap25j034.execute-api.eu-west-2.amazonaws.com","Referer":"https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/","upgrade-insecure-requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36","Via":"2.0 a3650115c5e21e2b5d133ce84464bea3.cloudfront.net (CloudFront)","X-Amz-Cf-Id":"0nDeiXnReyHYCkv8cc150MWCFCLFPbJoTs1mexDuKe2WJwK5ANgv2A==","X-Amzn-Trace-Id":"Root=1-597079de-75fec8453f6fd4812414a4cd","X-Forwarded-For":"50.129.117.14, 50.112.234.94","X-Forwarded-Port":"443","X-Forwarded-Proto":"https"},"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"path":"/dev/","accountId":"125002137610","resourceId":"qdolsr1yhk","stage":"dev","requestId":"0f2431a2-6d2f-11e7-b799-5152aa497861","identity":{"cognitoIdentityPoolId":null,"accountId":null,"cognitoIdentityId":null,"caller":null,"apiKey":"","sourceIp":"50.129.117.14","accessKey":null,"cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":null,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36","user":null},"resourcePath":"/","httpMethod":"POST","apiId":"j3azlsj0c4"},"body":{"msg":"update"},"isBase64Encoded":false}
My codebase depends on parameters like path, resource, isBase64Encoded, body, etc. What I am trying to achieve is, make the application portable (which can run on kubernetes). Is there a tool or a way that acts as an API gateway and passes an event like the one mentioned above while invoking this function ?
I have searched for tyk, traefik but none of them can generate an event like AWS API gateway and pass it to the function.
Not sure what you want to simulate the API gateway events, it's actually about the payload in json format which sent to lambda function.
eg.
aws lambda invoke --function-name docker-aws-cdk --region ap-southeast-1 --payload '{"action":"start", "target":"dev"}' outfile

Local Capybara Tests with chrome on mac uses certificate to authenticate - Looking for a way to prevent this

I'm currently writing capybara integration tests for a rails application. Is the driver is configured like this.
Capybara::Selenium::Driver.new app,
browser: :chrome
desired_capabilities: capabilities,
switches: ['--incognito']
The problem: During tests this chrome - even in incognito - automatically is authenticated on the website with certificates from my mac.
Is there any way to prevent the use of certificates other than deleting them? (we want to use :chrome and not :headless_chrome)
edit: found the root cause. A com.google.Chrome.plist file in my /Library/Preferences/ folder with some rules using automatically my company certificate for certain domains.
Assuming the certificates are being pulled from the MacOS keychain, you can try adding the --use-mock-keychain switch to your driver configuration.

Run a windows service as NT AUTHORITY/SYSTEM

Is there a way to run a windows local service with the integrated account NT AUTHORITY/SYSTEM ? (basically specify the "log on as" as NT AUTHORITY/SYSTEM)
Thanks,
Fred

When I copied text from Azure Cloud Shell terminal , copied string is incomplete

I selected bellow area and pressed command+C.
cloud shell capture
Following string is pasted from my clipboard.
You are viewing an offline list of runtimes. For up to dat
My browser is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
This is a known limitation.
Note: FireFox/IE may not support clipboard permissions properly.
For more details, refer "Limitations of Azure Cloud Shell".

cucumber javascript enabled features inside vagrant

i am a big fan of both cucumber and vagrant. i am using cucumber to drive development with a BDD style and have configured and setup my dev environment once in a vagrant vm so it can be easily distributed to other developers.
i've hit a snag when it comes to testing js on the vagrant vm. i'm using capybara alongside cucumber and have tried both selenium and capybara-webkit as js drivers.
selenium wanted me to install firefox. so i packaged up the vagrantbox fully expecting it not to work and installed firefox on the vm.. after that it complained about being unable to get a stable connection with firefox. exact error message: 'unable to obtain stable firefox connection in 60 seconds'
webkit complained about 'webkit_server: cannot connect to X server'.. i installed xserver-org and still no dice.
would much prefer if i didn't have to install my whole environment on my host in order to do testing as that would kind of defeat the purpose of having a distributable vagrant vm that has everything a dev needs to work on the app.
any ideas? i've encountered a similar problem with the notifications from guard, but that seems like not nearly as big a deal as this issue.
I think that all drivers require X, to be installed.
So on linux server I do not have how do it.
Other way it using Firefox from host machine via selenium remote.
It mean javascript will be run on remote Firefox on any machine.
Remote Selenium WebDriver not responding to Cucumber tests
http://code.google.com/p/selenium/wiki/RubyBindings
It work.
Run selenium server on host
java -jar selenium-server-standalone.jar
Changes in spec_helper.rb
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.http.use-cache"] = false
Capybara.register_driver :firefox_host do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => 'http://10.0.2.2:4444/wd/hub',
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
)
end
Capybara.server_port = 9300
Capybara.app_host = 'http://localhost:9300'
Capybara.javascript_driver = :firefox_host
Changes in Vagrantfile
config.vm.forward_port 9300, 9300
You may want to try running firefox headless.
http://www.alittlemadness.com/2008/03/05/running-selenium-headless/
This way, you can run tests without seeing them as well.
I ran into a similar issue. Try ssh'ing into your VM and executing xhost + from the command line. This disables access control and allows clients to connect from any host to access your display.
Also, you might need to export DISPLAY=:0 as well, because the webdriver will default to using this display when it launches Firefox.

Resources