2023년 1월 7일 토요일

Cause-Effect - draft

 https://www.geeksforgeeks.org/cause-effect-graphing-in-software-engineering/

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

2020년 1월 22일 수요일

Python Test Code 예제


import unittest

class ArithTest(unittest.TestCase):
    def runTest(self):
        """ Test addition and succeed. """
        self.failUnless(1 + 1 == 2, ‘one plus one fails!’)
        self.failIf(1 + 1 != 2, ‘one plus one fails again!’)
        self.failUnlessEqual(1 + 1, 2, ‘more trouble with one plus one!’)

def suite():
    suite = unittest.TestSuite()
    suite.addTest(ArithTest())
    return suite

if __name__ == ‘__main__’:
    runner = unittest.TextTestRunner()
    test_suite = suite()
    runner.run(test_suite)

Selenium WebDriver setting


public class LaunchWebDriver {

    private static final Logger logger = LoggerFactory.getLogger(UserPageTest.class);

    WebDriver driver;

    public LaunchWebDriver(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public WebDriver launchWebDriverMode(String headlessOnOff) {

        Path path = Paths.get("");
        String pathStr = path.toAbsolutePath().toString(); 
        logger.debug("pathStr={}", pathStr);

  /* MAC 과 WINDOWS chromedriver 분기 */
        if (isWindows()) {
            System.setProperty("webdriver.chrome.driver", pathStr + "//driver//chromedriver.exe");
        } else if (isMac()) {
            System.setProperty("webdriver.chrome.driver", pathStr + "//driver//chromedriver");
        } else {
            logger.error("지원하지 않는 OS 입니다.");
            return null;
        }

        ChromeOptions co = new ChromeOptions();
        logger.debug("computername={}", System.getenv("computername"));
        /* 공통 ChromeOptions 값. */
        co.addArguments("start-maximized");
        co.addArguments("enable-automation");
        co.addArguments("--disable-gpu");
        if (isWindows() && "NG-BF".equals(System.getenv("computername"))) {
            /* Jenkins 서버(windows)는 항상 headless 모드이다 (java.awt.headless = true) */
            logger.debug("headless Mode : NG-BF is Always headlessMode");
            /* jenkins 에만 추가되는 ChromeOptions 값. */
            co.addArguments("--no-sandbox");

        } else {
            if ("On".equals(headlessOnOff)) { // On / Off
                /* headless chrome */
                co.addArguments("--headless");
   }
        }

        driver = new ChromeDriver(co);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // 기본 대기 시간
        driver.manage().window().maximize();
        return driver;
    }

    public static boolean isWindows() {
        return (OS.isFamilyWindows());
    }
    public static boolean isMac() {
        return (OS.isFamilyMac());
    }
}



public abstract class BaseTest {
    public WebDriver driver;
    public LaunchWebDriver launchWebDriver;

    @BeforeClass
    public void setUp(){
        System.out.println("*** before class ****");
        String headlessOnOff ="On"; // headless = On or Off
        launchWebDriver = new LaunchWebDriver(driver);
        driver = launchWebDriver.launchWebDriverMode(headlessOnOff);
        if(driver == null){
            Assert.assertTrue(false);
        }
    }

    @AfterClass
    public void tearDown(){
        System.out.println("*** after class ****");
        if( driver != null)
            driver.quit();
    }

    @AfterTest
    public void afterTest() throws IOException {
        System.out.println("*** after test ****");
        if( LaunchWebDriver.isWindows() ){
            Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe /T");
        }
    }
}