Friday, 12 May 2023

intellij git

 1. show local change

  • open version control panel shortcut at bottom left
  • open local change tab
  • commit
  • revert
  • show diff (green add, grey delete)

2. show file history
  • vcs -> git -> show history

3. show line history
  • right click gutter and enable 'annotate'

Saturday, 25 March 2023

sql interview question

 1. find the 2nd largest value

select max(salary) as second_highest_salary
from employees
where salary < (select max(salary) from employees);

2. find total number and average value

select department_id, count(*) as total_employees, avg(salary) as average_salary
from employees
group by department_id;

3. find the employees who have the same job title as their manager

select e.employee_name, e.job_title
from employees e
join managers m on e.manager_id = m.manager_id
where e.job_title = m.job_title;

4. find the total revenue generated per month for a given year (e.g., 2022)

select extract(month from order_date) as month, sum(revenue) as total_revenue
from orders
where extract(year from order_date) = 2022
group by extract(month from order_date)
order by month

5. 万能公式

select t1.field_1,  aggregate(t2.field_2) as metric

from table_1 t1
join table_2 t2 on t1.field_3 = t2.field_4

group by t1.field_1                            //group field should be same as in select, otherwise make no sense
order by metric
limit 3

Thursday, 23 March 2023

selenium robot

 1. sections

  • lines starting with *** denote sections
  • they have a special meaning and serve as a way to organise the file
*** Settings ***
*** Variables ***
*** Test Cases ***
*** Keywords *** 

2. pre-defined keyword
  • selenium2Library comes with many predefined keywords like “Open Browser”

3. sample .robot file

*** Settings ***
Library           SeleniumLibrary

*** Variables ***
${URL}            https://the-internet.herokuapp.com/login
${BROWSER}        chrome

*** Test Cases ***
Login Test
    Open Browser To Login Page
    Input Credentials
    Verify Successful Login
    [Teardown]    Close Browser

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${URL}    ${BROWSER}

Input Credentials
    Input Text    id=username    tomsmith
    Input Text    id=password    SuperSecretPassword!
    Click Button    css=button[type="submit"]

Verify Successful Login
    Wait Until Page Contains    Welcome to the Secure Area
    Location Should Be    https://the-internet.herokuapp.com/secure


reference

Monday, 20 March 2023

linux/unix interview questions

 1. difference single quote, double quote, back tick

  • single quote: preserve literal value
  • double quote: variable expansion and command substitution
  • back tick: command substitution

2. difference between >, >>, 2>
  • >: redirect stdout to file and overwrite
  • >>: redirect stdout to file and append
  • 2>: redirect stderr to file and overwrite

3. command1 & command2 & wait
  • wait for concurrent and background running commands to finish

4. trap 'rm -f /tmp/tempfile' EXIT
  • do cleanup when script exit normal/abnormally
  • put this line at beginning of script

5. difference source vs exec a script
  • source execute in current shell, afterwards variable and function remains
  • exec create subshell to execute, afterwards nothing left

6. difference test, [], [[]]
  • test and [] are the same 
  • [[]] is better

jenkins

 1. terminology

  • node: a machine that's capable of executing pipelines or jobs, both controller and agent(slave) are node
  • executor: more like a work thread on a node
  • workspace: a directory on the node where pipeline or job is run
  • pipeline vs job: pipeline is more powerful and flexible, pipeline is defined using DSL as jenkinsfile in source code repo
  • reuseNode true: same agent node and Docker container are used for all stages of the pipeline, and the workspace directory remains the same across all stages

2, use a dockerfile
  • agent { dockerfile true }
  • create dockerfile and put in root of source repo


reference

awk

 1. program structure

BEGIN {awk-commands}

/pattern/ {awk-commands}      // body

END {awk-commands}


2. variable

$0: a special variable in awk that represents the entire line


3. commands

awk -f command.awk marks.txt

awk '/a/{++cnt} END {print "Count = ", cnt}' marks.txt

Thursday, 16 March 2023

selenium interview questions

 1. handle dynamic web elements in Selenium

  • use relative xpath or css selector
  • identify element based on surrounding elements
  • dynamic locator, e.g. contains(), startwith(), regex

2. assert vs. verify
  • verify does not stop the execution

3. handle popup, tab, window
  • get the handle, then switch to

4. upload and download
  • upload: sendkey() with filepath, or use AutoIT or Robot class
  • download: set some preferences, click download link

5. cookies
  • getCookies()
  • addCookie()
  • deleteCookie()

6. implicit wait, explicit wait, fluent wait
  • use explicit wait instead of implicit wait, DO NOT mix them together at same time
  • implicit wait poll the DOM for specified amount of time before trying to locate element
  • implicit wait is disabled by default and need to be enabled
  • explicit wait wait for certain condition to happen
  • fluent wait is a customised explicit wait

7. action
  • mouse and keyboard actions
  • mouse: doubleClick(), clickAndHold(), dragAndDrop(), moveToElement(), contextClick()
  • keyboard: sendKeys(), keyUp(), keyDown()

8. driver close vs quit
  • close: close current window
  • quit: quit session

9. alert and popup
  • alert: switchTo().alert()..dismiss()/.accept()/.sendKeys()

10. account login
  • navigate to login page
  • use api call to get auth token, then set browser cookie
  • refresh page, or navigate to the after-login page

11. selenium grid
  • hub is an instance of selenium server with config to distribute test
  • node is an instance of selenium server with browser capabilities that the node supports

12. handle iframe


reference