Katalon studio is a very easy to manage automation testing for web, mobile or windows application. On web automation testing sometime we need to check a url which will be redirected to another url. So we need to trace browser all network request to find out the source url before redirection. With katalon we could implement this very easily. Here I am giving sample code how we could manage it.
System.setProperty('webdriver.chrome.driver', DriverFactory.chromeDriverPath)
BrowserMobProxy proxy = new BrowserMobProxyServer()
proxy.start(8088)
DesiredCapabilities caps
WebDriver driver
ChromeOptions option = new ChromeOptions()
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT)
// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy)
caps = new DesiredCapabilities()
caps.setCapability(CapabilityType.PROXY, seleniumProxy)
caps.setBrowserName('chrome')
option.merge(caps)
proxy.newHar('proxyServer')
//Enable headless browser checking
option.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
driver = new ChromeDriver(option)
driver.get('https://ziyedbd.wordpress.com')
DriverFactory.changeWebDriver(driver)
WebUI.delay(2)
//Your all testing code goes in a test case and called on below lines
WebUI.callTestCase(findTestCase('testcase_file_location'), [:], FailureHandling.STOP_ON_FAILURE)
Har har = proxy.getHar()
File harfile = new File('Data Files/network.har')
har.writeTo(harfile)
def jsonSlurper = new JsonSlurper()
def data = jsonSlurper.parse(new FileReader(harfile))
data.log.entries.each({ def entry ->
def request = entry.request
if (request) {
URL url = new URL(request.url)
//Will print all network url
println(url)
}
})
proxy.stop()
To have all codes including import items, please go to this link of my github account