Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- oracle group by
- git 연동
- 톰캣 실시간 로그
- js 자동완성
- 테스트 자동화
- recursion example
- 해외주식 양도세 신고
- katalon 비교
- 피보나치함수 예제
- 한국투자증권 양도세 신고
- 한국투자증권 해외주식 양도세
- tomcat log
- bfs 미로탐색 java
- 재귀 예제
- CSTS 폭포수 모델
- 피보나치 예제
- 해외증권 양도세 한국투자증권
- Katalon Recorder 사용법
- katalon 자동화
- 최대공약수 예제
- 주식 양도세 신고방법
- 피보나치함수
- java.sql.SQLSyntaxErrorException
- katalon xpath
- katalon
- 홈택스 해외주식 양도세
- 재귀함수 예제
- katalon 사용법
- 국세청 해외주식 양도세 신고방식
- javascript 자동완성
Archives
- Today
- Total
엄지월드
Chrome Headless 본문
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.chrome.ChromeDriver as ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions as ChromeOptions
import org.openqa.selenium.remote.DesiredCapabilities as DesiredCapabilities
import org.openqa.selenium.remote.CapabilityType as CapabilityType
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType as WebUIDriverType
import com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver as ExistingRemoteWebDriver
import org.openqa.selenium.chrome.ChromeDriverService as ChromeDriverService
import org.apache.http.client.ClientProtocolException
import org.apache.http.client.HttpClient
import org.apache.http.impl.client.HttpClientBuilder
import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.StringEntity
/*
* Chrome default download path change!
*/
WebUIDriverType BrowserRunType = DriverFactory.getExecutedBrowser()
String str_BrowserRunType = BrowserRunType
//실행 브라우저가 chrome이 아닐경우 종료
if (!((str_BrowserRunType == 'Chrome') || (str_BrowserRunType == 'Chrome (headless)'))) {
WebUI.comment("${str_BrowserRunType}으로는 실행할 수 없습니다. Chrome, Chrome headless 로 실행하세요.")
CustomKeywords.'userdefinepkg.forcestop.FORCESTOP'()
}
'크롬 다운로드 경로 변경해서 실행'
System.setProperty('webdriver.chrome.driver', DriverFactory.getChromeDriverPath())
String downloadFilepath = System.getProperty('user.dir') + '\\Data Files\\download\\'
HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put('profile.default_content_settings.popups', 0)
chromePrefs.put('download.default_directory', downloadFilepath)
chromePrefs.put("download.prompt_for_download", false)
chromePrefs.put("download.directory_upgrade", true)
chromePrefs.put("safebrowsing.enabled", true)
chromePrefs.put('plugins.always_open_pdf_externally', true)
chromePrefs.put('cmd', 'Page.setDownloadBehavior')
chromePrefs.put('behavior', 'allow')
chromePrefs.put('plugins.plugins_disabled', ["Chrome PDF Viewer"])
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption('prefs', chromePrefs)
//options.addArguments("--disable-notifications")
options.addArguments("--window-size=1920x1280")
options.addArguments("--no-sandbox")
options.addArguments("--test-type")
options.addArguments("--disable-extensions")
//options.addArguments("--disable-infobars")
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
//실행타입이 headless 모드일 경우 옵션
if (str_BrowserRunType == 'Chrome (headless)') {
//WebUI.comment("${a}")
options.addArguments("--headless")
}
ChromeDriverService driverService = ChromeDriverService.createDefaultService()
ChromeDriver driver = new ChromeDriver(driverService, options)
Map<String, Object> commandParams = new HashMap<>()
commandParams.put("cmd", "Page.setDownloadBehavior")
Map<String, String> params = new HashMap<>()
params.put("behavior", "allow")
params.put("downloadPath", downloadFilepath)
commandParams.put("params", params)
ObjectMapper objectMapper = new ObjectMapper();
HttpClient httpClient = HttpClientBuilder.create().build();
String u = driverService.getUrl().toString() + "/session/" + driver.getSessionId() + "/chromium/send_command"
//println u
String command = null
try {
command = objectMapper.writeValueAsString(commandParams)
} catch(Exception e)
{
WebUI.comment("Error : ${e}")
CustomKeywords.'userdefinepkg.forcestop.FORCESTOP'()
}
HttpPost request = new HttpPost(u)
request.addHeader("content-type", "application/json")
request.setEntity(new StringEntity(command))
httpClient.execute(request)
DriverFactory.changeWebDriver(driver)
'QA > Groovy' 카테고리의 다른 글
API Call (0) | 2021.08.15 |
---|---|
Groovy 정규식 사용 (0) | 2019.11.20 |
Comments