Skip to content

Commit

Permalink
resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kazurayam committed Nov 27, 2024
1 parent cb85094 commit e303174
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 190 deletions.
174 changes: 11 additions & 163 deletions Keywords/com/kazurayam/ksbackyard/HighlightElement.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,24 @@ import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.keyword.internal.KeywordExecutor
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

/**
* This class implements 2 Keyword methods for Katalon Studio.
*
* <code>HighlightElement.on(TestObject to)</code> puts highlight on the specified HTML element.
*
* <code>HighlightElement.pandemic()</code> and <code>HighlightElement.pandemic(List<String> keywordsToAdd)</code> modifies some built-in WebUI Keywords dynamically so that they implicity invoke <code>.on(TestObject)</code> before
executing their own built-in processing (such as clicking the element).
*/
public class HighlightElement {

@Keyword
public static void on(TestObject testObject) {
drawOutline(testObject)
influence(testObject)
}

<<<<<<< HEAD
private static void drawOutline(TestObject testObject) {
=======
private static String DEFAULT_STYLE = 'outline: dotted red'
private static String highlightingStyle = DEFAULT_STYLE

private static void influence(TestObject testObject) {
>>>>>>> develop
try {
WebDriver driver = DriverFactory.getWebDriver()
List<WebElement> elements = WebUiCommonHelper.findWebElements(testObject, 20);
Expand All @@ -47,181 +37,40 @@ public class HighlightElement {
}
}

/**
* @return list of the built-in WebUI.* keywords that have "TestObject" as the 1st argument.
*/
public static Set<String> getHighlightableBuiltinKeywords() {
List<MetaMethod> metaMethods = WebUiBuiltInKeywords.metaClass.getMethods()
//println "metaMethods.size() is ${metaMethods.size()}"
Set<String> highlightables = new HashSet<String>()
for (MetaMethod method in metaMethods) {
if (method.isStatic() && method.isPublic()) {
Class<?>[] parameterTypes = method.nativeParameterTypes
// select a Keyword if it requires a TestObject as the 1st argument
if ( parameterTypes.size() > 0 && parameterTypes[0].is(TestObject.class)) {
//println "method: ${method.getName()}(${parameterTypes[0].getName()})"
highlightables.add(method.getName())
}
}
}
return highlightables
}


/**
* these keywords are "highlighting" as default
*/
public static final Set<String> DEFAULT_HIGHLIGHTING_KW = new HashSet([
private static List<String> influencedKeywords = [
'click',
'selectOptionByIndex',
'selectOptionByLabel',
'selectOptionByValue',
'setEncryptedText',
'setText'
<<<<<<< HEAD
])

// instance variable
private final Set<String> highlightingKW

/**
* constructor
*/
HighlightElement() {
this.highlightingKW = new HashSet(DEFAULT_HIGHLIGHTING_KW)
}
=======
]
>>>>>>> develop

/**
* change some of methods of WebUiBuiltInKeywords so that they call HighlightElement.on(testObject)
* before invoking their original method body.
<<<<<<< HEAD
*
* This method is implemented using Groovy Metaprogramming technique. See
=======
*
>>>>>>> develop
* http://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#metaprogramming
*
* @param keywordsToAdd you can specify additional keywords to turn "highlighting"
*/
@Keyword
<<<<<<< HEAD
public void pandemic(List<String> keywordsToAdd = []) {
this.markKeywords(keywordsToAdd)
Set<String> influencedKeywords = this.getHighlightingKeywords()
=======
public static void pandemic(String style, List<String> keywords) {
highlightingStyle = style
influencedKeywords.addAll(keywords)
>>>>>>> develop
WebUiBuiltInKeywords.metaClass.'static'.invokeMethod = { String name, args ->
if (name in influencedKeywords) {
TestObject to = (TestObject)args[0]
HighlightElement.on(to)
}
return delegate.metaClass.getMetaMethod(name, args).invoke(delegate, args)
}
}

<<<<<<< HEAD
/**
*
* @param keywordsToAdd
*/
public void markKeywords(List<String> keywordsToAdd = []) {
Objects.requireNonNull(keywordsToAdd)
Set<String> highlightables = getHighlightableBuiltinKeywords()
keywordsToAdd.each { kw ->
// if the specified keyword is highlight-able, then accept it
if (highlightables.contains(kw)) {
//println "specified keyword \"${kw}\" is marked as highlight-able"
this.highlightingKW.add(kw)
} else {
println "specified keyword \"${kw}\" is not highlight-able; just ignored"
def result
try {
result = delegate.metaClass.getMetaMethod(name, args).invoke(delegate, args)
} catch(Exception e) {
System.out.println("Handling exception for method $name")
}
return result
}
}

/**
*
* @return
*/
public Set<String> getHighlightingKeywords() {
return highlightingKW.clone()
}


// previous implementation of pandemic without Groovy's Metaprogramming
/*
@Keyword
public static void pandemic() {
// click() with FailuraHandling
WebUiBuiltInKeywords.metaClass.static.click = { TestObject to, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "click", to, flowControl)
}
// click() without FailuraHandling
WebUiBuiltInKeywords.metaClass.static.click = { TestObject to ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "click", to)
}
// selectOptionByIndex() with FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByIndex = { TestObject to, Object range, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByIndex", to, range, flowControl)
}
// selectOptionByIndex() without FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByIndex = { TestObject to, Object range ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByIndex", to, range)
}
// selectOptionByLabel() with FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByLabel = { TestObject to, String value, boolean isRegex, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByLabel", to, value, isRegex, flowControl)
}
// selectOptionByLabel() without FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByLabel = { TestObject to, String value, boolean isRegex ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByLabel", to, value, isRegex)
}
// selectOptionByValue() with FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByValue = { TestObject to, String value, boolean isRegex, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByValue", to, value, isRegex, flowControl)
}
// selectOptionByValue() without FailureHandling
WebUiBuiltInKeywords.metaClass.static.selectOptionByValue = { TestObject to, String value, boolean isRegex ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "selectOptionByValue", to, value, isRegex)
}
// setEncryptedText() with FailureHandling
WebUiBuiltInKeywords.metaClass.static.setEncryptedText = { TestObject to, String encryptedText, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "setEncryptedText", to, encryptedText, flowControl)
}
// setEncryptedText() without FailureHandling
WebUiBuiltInKeywords.metaClass.static.setEncryptedText = { TestObject to, String encryptedText ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "setEncryptedText", to, encryptedText)
}
// setText() with FailureHandling
WebUiBuiltInKeywords.metaClass.static.setText = { TestObject to, String text, FailureHandling flowControl ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "setText", to, text, flowControl)
}
// setText() without FailureHandling
WebUiBuiltInKeywords.metaClass.static.setText = { TestObject to, String text ->
HighlightElement.on(to)
KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.PLATFORM_WEB, "setText", to, text)
}
}
*/
}
=======
@Keyword
public static void pandemic() {
pandemic(DEFAULT_STYLE, [])
Expand All @@ -236,5 +85,4 @@ public class HighlightElement {
public static void pandemic(List<String> keywords) {
pandemic(DEFAULT_STYLE, keywords)
}
}
>>>>>>> develop
}
23 changes: 3 additions & 20 deletions Scripts/TC1/Script1547070867765.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@ import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

/**
* TC1
<<<<<<< HEAD
*/
=======
*
* This script visits the page at https://katalon-demo-cura.herokuapp.com/
*
* This script visits the page at https://katalon-demo-cura.herokuapp.com/
* and the linked pages while highlighting elements with red border.
* This script repeats explicitly calling a custome keyword to put the highlight
* so that this script looks tedius.
*/

>>>>>>> develop
// open browser and navigate to the AUT
WebUI.openBrowser('')
WebUI.setViewPortSize(1024, 1024)
WebUI.navigateToUrl('https://katalon-demo-cura.herokuapp.com/')
<<<<<<< HEAD

// modify WebUI.* keywords which take TestObject as arg0
// so that they call Highlight.on() automatically
CustomKeywords.'com.kazurayam.ksbackyard.HighlightElement.pandemic'()

WebUI.click(findTestObject('Page_CURA Healthcare Service_top/a_Make Appointment'))
=======
WebUI.delay(1)

TestObject h1_CURA = findTestObject('Page_CURA Healthcare Service_top/h1_CURA Healthcare Service')
Expand All @@ -40,7 +28,6 @@ WebUI.verifyElementPresent(a_MakeAppointment, 10)
// highlight the element
CustomKeywords.'com.kazurayam.ksbackyard.HighlightElement.on'(a_MakeAppointment)
WebUI.click(a_MakeAppointment)
>>>>>>> develop
WebUI.delay(1)

TestObject input_username = findTestObject('Page_CURA Healthcare Service_login/input_Username_username')
Expand All @@ -63,13 +50,9 @@ CustomKeywords.'com.kazurayam.ksbackyard.HighlightElement.on'(select_Facility)
WebUI.selectOptionByIndex(select_Facility, 0)
WebUI.delay(1)

<<<<<<< HEAD
WebUI.click(findTestObject('Page_CURA Healthcare Service_appointment/input_Apply for hospital readm'))
=======
TestObject input_hospital_readm = findTestObject('Page_CURA Healthcare Service_appointment/input_Apply for hospital readm')
CustomKeywords.'com.kazurayam.ksbackyard.HighlightElement.on'(input_hospital_readm)
WebUI.click(input_hospital_readm)
>>>>>>> develop
WebUI.delay(1)

TestObject input_Medicaid = findTestObject('Page_CURA Healthcare Service_appointment/input_Medicaid_programs')
Expand Down Expand Up @@ -97,4 +80,4 @@ CustomKeywords.'com.kazurayam.ksbackyard.HighlightElement.on'(a_Go_to_Homepage)
WebUI.click(a_Go_to_Homepage)
WebUI.delay(1)

WebUI.closeBrowser()
WebUI.closeBrowser()
7 changes: 1 addition & 6 deletions Test Cases/TC0.tc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
<name>TC0</name>
<tag></tag>
<comment></comment>
<<<<<<< HEAD
<testCaseGuid>acc23931-de48-4b92-a6be-771f1804f416</testCaseGuid>
=======
<recordOption>OTHER</recordOption>
<testCaseGuid>78b3ca65-5cb5-4a9e-b949-e19dbccff62a</testCaseGuid>
>>>>>>> develop
<testCaseGuid>dc80fd5a-b8cf-4535-a917-1959603a772c</testCaseGuid>
</TestCaseEntity>
1 change: 0 additions & 1 deletion Test Cases/TC1.tc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<name>TC1</name>
<tag></tag>
<comment></comment>
<recordOption>OTHER</recordOption>
<testCaseGuid>d58ff4fd-fb65-4bf0-aa81-58c745a3616b</testCaseGuid>
</TestCaseEntity>
2 changes: 2 additions & 0 deletions Test Suites/TS1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<isReuseDriver>false</isReuseDriver>
<isRun>true</isRun>
<testCaseId>Test Cases/TC0</testCaseId>
<usingDataBindingAtTestSuiteLevel>true</usingDataBindingAtTestSuiteLevel>
</testCaseLink>
<testCaseLink>
<guid>8ad65bd7-b4bf-4e6f-8219-a89f05659de9</guid>
Expand All @@ -29,5 +30,6 @@
<isReuseDriver>false</isReuseDriver>
<isRun>true</isRun>
<testCaseId>Test Cases/TC2</testCaseId>
<usingDataBindingAtTestSuiteLevel>true</usingDataBindingAtTestSuiteLevel>
</testCaseLink>
</TestSuiteEntity>

0 comments on commit e303174

Please sign in to comment.