Monday, 30 October 2017

protractor with typescript

1. files
  • package.json (npm specific, same as pom.xml in maven)
  • tsconfig.json (typescript specific, typescript project file)
  • vscode cucumber plugin and cucumber-mapper plugin

2. setup
  • npm install -g protractor (global install, can use in command line without specify path)
  • npm install protractor (local install, used by require(), can also use in command line if specify path)
  • npm list <package_name> (list local packages)
  • npm list -g <package_name>  (list globally packages)
  • npm list -g --depth=0 (list globally user installed top level package)
  • npm install <package_name> --save (used for production)
  • npm install <package_name> --save-dev (used for development)
  • both write to package.json -> dependencies
  • npm install (install dependencies in ./package.json)
  • npm run update (install update)

3.tsconfig.json
  • it lists the files belonging to the project as well as compiler options
  • outFile (.ts files are converted to .js and output here, help sourceMap to find)
  • @types, typeRoots and types
  • by default all visible “@types” packages are included in your compilation
  • if typeRoots is specified, only packages under typeRoots will be included
  • if types is specified, only packages listed will be included

4. config.js
  • browser.ignoreSynchronization = true      //this is used for non-angular app, now become selemium js and should use explicit wait
  • browser.ignoreSynchronization = false     //this is used for angular app, and no wait is needed for angular element
  • browser.ignoreSynchronization is depreciated, now should use browser.waitForAngularEnabled
  • SELENIUM_PROMISE_MANAGER: false     //disable control flow
  • when control flow is disabled, can use async/await or promise chain (i.e. .then()) to synchronise command
  • when control flow is enabled, use async/await has conflict with control flow, so need to use promise chain

5. promise & control flow
  • all webdriver js (i.e. protractor) functions are async and return promises
  • webdriver js maintain a queue of pending promises called control flow 

5. debug typescript in vscode
  • "sourceMap": true in tsconfig.json so that you can debug .ts
  • configure 'launch.json' file correctly, it can contain multiple configurations (choose one when debugging)

5. shortcut
  • ctrl+shift+f (search all)
  • f5 (debug)
  • ctrl+f5 (run)
  • ctrl+p (open recent files)

6. await/async
  • async function return a promise
  • await can only be used in async function
  • await make javascript wait until promise resolve

7. webdriver js
  • when promise manager is disabled (SELENIUM_PROMISE_MANAGER=0), each command will execute as soon as it's scheduled
  • when promise manager is enabled, each command will block until the previous command complete
  • turn off control flow (SELENIUM_PROMISE_MANAGER: false) when using async/await
  • setDefaultTimeout(60 * 1000); to change default timeout

8.  npm run or npm test or npm start
  • your current package directory's bin directory is placed at the front of your path

9. npm ls selenium-webdriver

10. node js
  • single threaded
  • concurrency model based on event loop and registered callback

11. style guide
  • make test independent at least at file level

12. debug protractor in vscode
  • .vscode/launch.json

"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
"stopOnEntry": false,
"args": ["${workspaceRoot}/protractor.conf.js"],


reference

Sunday, 22 October 2017

aws

1. aws cli credential (also see item 9)
  • '~/.aws/config' file, or
    '~/.aws/credentials' file, or
    'AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY' env variable, or
    ec2 instance profile credentials
  • 'credentials' stores access keys
  • 'config' stores other configuration like region and output format
  • no conflict between 'credentials' and 'config', aws cli or java sdk will look at both file
  • when using aws cli, set 'AWS_PROFILE' env variable or use --profile flag in cli command if profile is not default
  • when using java sdk, use ProfileCredentialsProvider if profile is not default

2. iam user/group/role/policy/profile
  • user is used to sign in  (aws iam list-users)
  • group is collection of users
  • role is collection of policies (user can have multiple roles)
  • policy=permission
  • profile is a settings file

3. arn 
  • amazon resource name
  • arn:partition:service:region:account:resource        //format
  • arn:aws:iam::998355367879:user/test-user            //example: user

4. kinesis
  • streaming data service
  • consumer: firehose, data analytics etc
  • pip3 install kines
  • kines walk streamotion-gam-datalake-nonprod  000000000120 -l -f    //000000000120 is one of the shards id. shard == partition 

5. commands
  • aws configure list-profiles         //show all profiles
  • aws configure list                      //show current profile
  • aws sts get-caller-identity         //current user, role

6. profile
  • [default] is used when running cmd without --profile param
  • export AWS_PROFILE=user1                  //use the named profile

7. cli settings precedence (which override which)
  • command line option                    //--profile
  • environment variable                    //export 
  • credentials file
  • config file

8. ec2 key pair
  • when ec2 instance boost, public key is stored in instance
  • when connecting to ec2 instance, you must specify private key

9. set credentials when use java sdk or aws cli
  • option 1: use '~/.aws/credentials' file to set up credential (not 'config' file)
[default]
role_arn = arn:aws:iam::111111111111:role/group-xxxxx-xxxxx
source_profile = okta
region = ap-southeast-2

[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

  • option 2: use aws environment variable to set up credentials
export AWS_ACCESS_KEY_ID=your_access_key_id
export AWS_SECRET_ACCESS_KEY=your_secret_access_key
export AWS_REGION=your_aws_region
  • aws env variable take precedence over ~/.aws/credentials, but in general, it's best practice to store credentials in the ~/.aws/credentials file, and load the credentials in your code using the AWSCredentialsProvider class
AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();


10. aws lambda vs ec2
  • ec2: need to provision container, orchestration, scaling
  • lambda: taken care of by aws

  • ec2: need to take care of security layer access
  • lambda: taken care of by aws

  • ec2: combined with ALB, has no timeout limit
  • lambda: combined with api gateway, has timeout limit of 15min for lambda and 30 sec for gateway

  • ec2: need to config auto scaling group
  • lambda: taken care of by aws

  • ec2: always available
  • lambda: on demand

  • ec2: cold start not needed unless for a new container
  • lambda: cold start needed

11. api gateway
  • default max integration timeout limit 30 sec

12. skill used at work
  • management console, cli, sdk
  • s3, secret manager, kinesis, sqs, nosql
  • ec2 - elastic compute cloud (vm)
  • ecs - elastic container service (docker)

reference