Pages - Menu

2019年10月30日 星期三

[Katalon Studio]瀏覽器開啟及關閉

前言

目前的計畫是,根據程式碼,逐步的往下介紹。
為什麼要關閉瀏覽器?前面有提過,當程式執行太久,記憶體會咬住無法釋放。
故我直接把瀏覽器關閉再開啟,強迫他釋放記憶體,也避免卡住。



正文


def open(baseUrl){
    WebUI.openBrowser('')
   
    autoit_prj = 'C:\\Users\\Administrator\\Desktop\\Windchill.exe'
    Runtime.getRuntime().exec(autoit_prj)
   
    Thread.sleep(1000)
   
    //Sample URL. Please change it to your authentication URL
    WebUI.navigateToUrl(baseUrl)   
}

呼叫

String baseUrl = 'http://plm.xxxx.com.tw/Windchill'
open(baseUrl)
def driver = DriverFactory.getWebDriver()
selenium = new WebDriverBackedSelenium(driver, baseUrl)

Date date = new Date()
String today = date.format('yyyy/MM/dd HH:mm')
int count = 1
for (def index : (0..data.getRowNumbers() - 1)) {
   
    if(count == 20){       
        //driver.close()
        //driver = null
       
        WebUI.closeBrowser()
               
        Thread.sleep(3000)
        open(baseUrl)   
        driver = DriverFactory.getWebDriver()
        selenium = new WebDriverBackedSelenium(driver, baseUrl)
        delayTime(3000)
        count = 0
    }
}

記下跑迴圈前的時間,再寫備註將日期時間填入,
當新增20筆料號的英文品名後,將瀏覽器關閉後重開。
重開後,會再去呼叫autoIT做登入的動作。
之前有試過用driver.close()及driver清空的方式,將暫存清掉,再關閉瀏覽器。
最後是直接使用Katalon 的函數 WebUI.closeBrowser()關閉瀏覽器。
ref.
How to get current system date and time in Java/ Selenium

沒有留言:

張貼留言