2020년 11월 16일 월요일

.gitignore 파일 규칙

.gitignore 파일이란?

사용자가 원하지 않는 파일들을 자동으로 git commit 대상에서 제외하도록 규칙을 작성


원하지 않는 파일은?

- IDE tool과 관련된 설정파일

- 언어의 빌드 결과물, 로그 패키지 관련 파일

- 사용자가 제외하기 원하는 파일 등

- gitignore 참고 url : https://github.com/github/gitignore


.gitignore 파일 위치는?

프로젝트 최상단 폴더에 위치시키면 된다.

.gitignore 파일 규칙

- #은 주석 역할

- 표준 glob 패턴 사용

- / 를 사용하면 규칙이 프로젝트 전체에 적용되지 않음

- / 로 끝나는 것은 폴더로 인식

- ! 를 사용하면 무시되지 않음


.gitignore sample

#*#
.#*
*~
_site/
*/src/META-INF/
*/src/main/java/META-INF/
bin/
target/
.classpath
.project
.DS_Store
.settings/
.springBeans
*.iml
*.iws
*.ipr
.idea/
code/
cargo-installs/
atlassian-ide-plugin.xml
deploy/
# 모든 확장자 .txt 파일을 무시
*.txt

# 무시하는 모든 확장자 .txt 파일들 중에서 test.txt 파일은 무시하지 않음
!test.txt

# Project/
# ㄴ.gitignore
# ㄴsrc/
# ㄴabc.txt
# ㄴTODO/
# ㄴtest1.txt
# ㄴTODO/
# ㄴtest2.txt
#
# 현재 폴더 중에서 TODO 폴더에 있는 모든 파일을 무시
# (즉, test1.txt 파일만 무시되고 test2.txt 파일은 무시되지 않음)
/TODO

# 프로젝트 전체 폴더 중 TODO라는 폴더명을 사용하는 TODO 폴더의 하위 파일은 모두 무시
# (즉, test1.txt 파일과 test2.txt 파일 모두 무시됨)
TODO/

# Project/
# ㄴ.gitignore
# ㄴdoc/
# ㄴa.txt
# ㄴb.pdf
# ㄴserver/
# ㄴaa.txt
# ㄴbb.pdf
#
# 현재 폴더 중에서 doc 폴더 바로 밑에 있는 .txt 확장자 파일만 모두 무시
# 단, doc/server/aa.txt 와 같은 형식에서는 .txt 확장자 파일이 무시되지 않음
doc/*.txt

# 현재 폴더 중에서 doc 폴더 하위에 있는 .pdf 확장자 파일은
# doc 폴더 하위 어떤 폴더에 들어 있더라도 모두 무시
# (즉, b.pdf 파일과 bb.pdf 파일 모두 무시됨)
doc/**/*.pdf

Git 원격 및 로컬 디렉토리 연동방법

1. git init                                        //저장소 초기화

2. git add 파일명(폴더)                   //파일 및 폴더 추가

3. git commit -m "first commit"    //commit

4. git remote add origin URL        //원격 저장소 연동

5. git push -u origin master <리모트 저장소 이름> <push할 브랜치 이름>    //파일 및 폴더 push

2020년 11월 9일 월요일

element.click으로 브라우져의 새 탭이 열렸을 때 driver 제어 방법

 element.click 으로 같은 화면에서 UI가 갱신되는 게 아니라 새 탭이 열렸을 경우,

selenium driver에 알려줘야 한다.

그렇지 않으면 기존에 오픈 된 브라우져의 화면에서 element를 찾게 되어 no such element 에러 메시지를 보게 된다.


[How to]

//driver 제어를 위한 현재 열려있는 브라우져 확인
String parentWindow = driver.getWindowHandle();

element.click();


String childWindow = null;
for(String childs: driver.getWindowHandles()){
if(!childs.equals(parentWindow)){
childWindow = childs;
break;
}
}
driver.switchTo().window(childWindow);

2020년 11월 6일 금요일

Hamcrest Test Framework

 Hamcrest란?

test framework을 이용하여 단위 테스트 진행 시 assert를 유연하게 하기 위해 matcher를 이용하여 좀 더 쉽고 확장성 있는 assert를 하기 위해 만들어진 framework이다. 

Hamcrest는 처음부터 test framework과 통합되도록 설계되어 JUnit, TestNG와 함께 사용할 수 있다.


maven dependency

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>

Hamcrest code

assertThat(actual, is(equalTo(expedted);
assertThat(result, instanceof String);
assertThat(result, is(hasItem(anyOf(equalTo("x", equalTo("y"), equalTo("z"))))));

Hamcrest Matcher 

allOf - matches if all matchers match (short circuits)
anyOf - matches if any matchers match (short circuits)
not - matches if the wrapped matcher doesn’t match and vice
equalTo - test object equality using the equals method
is - decorator for equalTo to improve readability
hasToString - test Object.toString
instanceOf, isCompatibleType - test type
notNullValue, nullValue - test for null
sameInstance - test object identity
hasEntry, hasKey, hasValue - test a map contains an entry, key or value
hasItem, hasItems - test a collection contains elements
hasItemInArray - test an array contains an element
closeTo - test floating point values are close to a given value
greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo
equalToIgnoringCase - test string equality ignoring case
equalToIgnoringWhiteSpace - test string equality ignoring differences in runs of whitespace
containsString, endsWith, startsWith - test string matching