-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZK-5135: Make a client error more helpful for debug
- Loading branch information
1 parent
702639c
commit 7bab971
Showing
13 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<zk> | ||
<client-config> | ||
<debug-js>true</debug-js> | ||
<send-client-errors>true</send-client-errors> | ||
</client-config> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
F100-ZK-5135.zul | ||
Purpose: | ||
Description: | ||
History: | ||
Fri Jan 12 14:53:31 CST 2024, Created by rebeccalai | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk> | ||
<label multiline="true"> | ||
1. enable debug-js and send-client-errors with | ||
<client-config> | ||
<debug-js>true</debug-js> | ||
<send-client-errors>true</send-client-errors> | ||
</client-config> | ||
2. should see 'custom error message' in the error box, else override zk.errorPush not working. | ||
3. should see error stack trace in the browser console and the server log. | ||
</label> | ||
<script><![CDATA[ | ||
zk.afterLoad('zk', function () { | ||
zk.errorPush = function (msg) { | ||
zk._Erbx.push('custom error message'); | ||
}; | ||
}); | ||
]]></script> | ||
<textbox constraint="//aab\o/"/> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5135Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* F100_ZK_5135Test.java | ||
Purpose: | ||
Description: | ||
History: | ||
Mon Jan 15 17:01:07 CST 2024, Created by rebeccalai | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.zats.test2; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.contains; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.openqa.selenium.logging.LogType; | ||
import org.slf4j.Logger; | ||
|
||
import org.zkoss.test.webdriver.ExternalZkXml; | ||
import org.zkoss.test.webdriver.ForkJVMTestOnly; | ||
import org.zkoss.test.webdriver.WebDriverTestCase; | ||
import org.zkoss.zk.ui.impl.DesktopImpl; | ||
|
||
@ForkJVMTestOnly | ||
public class F100_ZK_5135Test extends WebDriverTestCase { | ||
@RegisterExtension | ||
public static final ExternalZkXml CONFIG = new ExternalZkXml("/test2/F100-ZK-5135-zk.xml"); | ||
|
||
@Test | ||
public void test() throws Exception { | ||
Logger logger = mock(Logger.class); | ||
setFinalStatic(DesktopImpl.class.getDeclaredField("log"), logger); | ||
connect(); | ||
waitResponse(); | ||
assertTrue(jq(".z-error").text().contains("custom error message")); | ||
// check browser log | ||
driver.manage().logs().get(LogType.BROWSER).getAll().stream().findFirst().ifPresent(log -> | ||
assertTrue(log.getMessage().contains("SimpleConstraint._init"))); | ||
// check server log | ||
verify(logger, atLeastOnce()).error(anyString(), contains("F100-ZK-5135.zul"), | ||
contains("SimpleConstraint._init")); | ||
} | ||
|
||
// https://stackoverflow.com/a/30703932 | ||
private static void setFinalStatic(Field field, Object newValue) throws Exception { | ||
field.setAccessible(true); | ||
Field modifiersField = Field.class.getDeclaredField("modifiers"); | ||
modifiersField.setAccessible(true); | ||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); | ||
field.set(null, newValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters