Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified JSONPayload to replace non-utf8 character as � #654

Closed
wants to merge 4 commits into from
Closed

modified JSONPayload to replace non-utf8 character as � #654

wants to merge 4 commits into from

Conversation

jakobtak
Copy link

@jakobtak jakobtak commented Jan 17, 2023

I've got an Error failed to convert to UTF8 when I was getting a page source from my device.
It was an WebView, so I think it contained some non UTF8 characters in the page. In order to continue the test, I thought it's better to return some page information rather than raising UTF8 conversion error. Therefore I've created the pull request. Thank you.

2023-01-08 13:50:41:798 [HTTP] --> POST /wd/hub/session/cfd06d4f-e25b-4ae8-a4d0-aa5668f01d19/execute/sync
2023-01-08 13:50:41:798 [HTTP] {"script":"mobile: source","args":[{"format":"description"}]}
2023-01-08 13:50:41:813 [W3C (cfd06d4f)] Calling AppiumDriver.execute() with args: ["mobile: source",[{"format":"description"}],"cfd06d4f-e25b-4ae8-a4d0-aa5668f01d19"]
2023-01-08 13:50:41:814 [XCUITest] Executing command 'execute'
2023-01-08 13:50:41:818 [WD Proxy] Matched '/source?format=description' to command name 'getPageSource'
2023-01-08 13:50:41:818 [WD Proxy] Proxying [GET /source?format=description] to [GET http://127.0.0.1:8204/session/A49ED027-78B2-4B05-A38F-246F2DD61F60/source?format=description] with no body
2023-01-08 13:50:41:826 [Xcode] 2023-01-08 13:50:41.790863+0900 WebDriverAgentRunner-Runner[507:11854] Request URL /session/A49ED027-78B2-4B05-A38F-246F2DD61F60/source?format=description -- http://127.0.0.1:8204/ | Params {
2023-01-08 13:50:41:826 [Xcode]     format = description;
2023-01-08 13:50:41:826 [Xcode]     sessionID = "A49ED027-78B2-4B05-A38F-246F2DD61F60";
2023-01-08 13:50:41:826 [Xcode] } | Arguments {
2023-01-08 13:50:41:826 [Xcode] }
2023-01-08 13:50:41:826 [Xcode] 
2023-01-08 13:50:41:838 [Xcode] 2023-01-08 13:50:41.802205+0900 WebDriverAgentRunner-Runner[507:11854] Getting the most recent active application (out of 1 total items)
2023-01-08 13:50:41:838 [Xcode] 
2023-01-08 13:50:41:840 [Xcode]     t =    44.43s Get all elements bound by accessibility element for: Children matching type Any
2023-01-08 13:50:41:840 [Xcode] 
2023-01-08 13:50:41:854 [Xcode]     t =    44.43s     Requesting snapshot of accessibility hierarchy for app with pid 513
2023-01-08 13:50:41:854 [Xcode] 
2023-01-08 13:50:42:848 [Xcode]     t =    45.44s     Find: Children matching type Any
2023-01-08 13:50:42:848 [Xcode] 
2023-01-08 13:50:42:890 [Xcode]     t =    45.48s Requesting snapshot of accessibility hierarchy for app with pid 513
2023-01-08 13:50:42:890 [Xcode] 
2023-01-08 13:50:44:036 [Xcode] 2023-01-08 13:50:44.001704+0900 WebDriverAgentRunner-Runner[507:12011] Error Domain=com.facebook.WebDriverAgent Code=1 "Cannot take a screenshot within 20000 ms timeout" UserInfo={NSLocalizedDescription=Cannot take a screenshot within 20000 ms timeout}
2023-01-08 13:50:44:036 [Xcode] 
2023-01-08 13:50:45:105 [Xcode] 2023-01-08 13:50:45.070423+0900 WebDriverAgentRunner-Runner[507:12011] Error Domain=com.facebook.WebDriverAgent Code=1 "Cannot take a screenshot within 20000 ms timeout" UserInfo={NSLocalizedDescription=Cannot take a screenshot within 20000 ms timeout}
2023-01-08 13:50:45:105 [Xcode] 
2023-01-08 13:50:45:732 [Xcode]     t =    48.32s Find: Children matching type Any
2023-01-08 13:50:45:733 [Xcode] 
2023-01-08 13:50:45:733 [Xcode]     t =    48.32s Find: Identity Binding
2023-01-08 13:50:45:733 [Xcode] 
2023-01-08 13:50:45:837 [Xcode]     t =    48.43s Find the Application 'com.my.app'
2023-01-08 13:50:45:837 [Xcode]     t =    48.43s     Requesting snapshot of accessibility hierarchy for app with pid 513
2023-01-08 13:50:45:837 [Xcode] 
2023-01-08 13:50:46:622 [Xcode] 2023-01-08 13:50:46.585560+0900 WebDriverAgentRunner-Runner[507:11854] *** Assertion failure in -[FBResponseJSONPayload dispatchWithResponse:](), FBResponseJSONPayload.m:45
2023-01-08 13:50:46:622 [Xcode] 
2023-01-08 13:50:46:642 [Xcode] 2023-01-08 13:50:46.607696+0900 WebDriverAgentRunner-Runner[507:11854] Response URL /session/A49ED027-78B2-4B05-A38F-246F2DD61F60/source?format=description -- http://127.0.0.1:8204/ | Status 500
2023-01-08 13:50:46:642 [Xcode] 
2023-01-08 13:50:46:652 [WD Proxy] Got response with status 500: {"value":{"error":"unknown error","message":"Valid JSON must be responded, error of Error Domain=NSCocoaErrorDomain Code=3852 \"The string 0x282dd90b0 failed to convert to UTF8\" UserInfo={NSDebugDescription=The string 0x282dd90b0 failed to convert to UTF8}","traceback":"(\n\t0   CoreFoundation                      0x0000000182096d50 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 597328\n\t1   libobjc.A.dylib                     0x00000001993fb6a8 objc_exception_throw + 56\n\t2   Foundation                          0x0000000183867afc 534D37B5-2B79-3993-AB18-822606B22ABF + 1190652\n\t3   WebDriverAgentLib                   0x00000001063357ac -[FBResponseJSONPayload dispatchWithResponse:] + 312\n\t4   WebDriverAgentLib                   0x0000000106316354 -[FBRoute_TargetAction mountRequest:intoResponse:] + 232\n\t5   WebDriverAgentLib                   0x0000000106301864 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 520\n\t6   WebDriverAgentLib                   0x000000010633858c -[RoutingHTTPServer han...
2023-01-08 13:50:46:653 [W3C] Matched W3C error code 'unknown error' to UnknownError
2023-01-08 13:50:46:655 [W3C (cfd06d4f)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Valid JSON must be responded, error of Error Domain=NSCocoaErrorDomain Code=3852 "The string 0x282dd90b0 failed to convert to UTF8" UserInfo={NSDebugDescription=The string 0x282dd90b0 failed to convert to UTF8}
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at errorFromW3CJsonCode (/opt/apps/appium/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at ProxyRequestError.getActualError (/opt/apps/appium/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at JWProxy.command (/opt/apps/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at processTicksAndRejections (internal/process/task_queues.js:95:5)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at XCUITestDriver.proxyCommand (/opt/apps/appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at XCUITestDriver.mobileGetSource (/opt/apps/appium/node_modules/appium-xcuitest-driver/lib/commands/source.js:50:10)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at XCUITestDriver.executeMobile (/opt/apps/appium/node_modules/appium-xcuitest-driver/lib/commands/execute.js:131:10)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at XCUITestDriver.execute (/opt/apps/appium/node_modules/appium-ios-driver/lib/commands/execute.js:15:12)
2023-01-08 13:50:46:656 [W3C (cfd06d4f)]     at XCUITestDriver.execute (/opt/apps/appium/node_modules/appium-xcuitest-driver/lib/commands/execute.js:16:10)
2023-01-08 13:50:46:658 [HTTP] <-- POST /wd/hub/session/cfd06d4f-e25b-4ae8-a4d0-aa5668f01d19/execute/sync 500 4859 ms - 1858

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 17, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jakobtak / name: Jakob Tak (3d30a19)

@jakobtak
Copy link
Author

Sorry, I force pushed to change the author, I used my work acc.

@KazuCocoa
Copy link
Member

Thank you!
Could you add something test code?

*/
+ (NSString*) makeValidUTF8:(NSString*) stringToCheck
{
if (![FBResponseJSONPayload isValidUTF8 :stringToCheck])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same below. New methods must follow the same style as the other code

NSMutableString* fixedUp = [NSMutableString stringWithString:@""];
for (NSUInteger i = 0; i < [stringToCheck length]; i++)
{
@autoreleasepool

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. ARC is enabled for this project

- (instancetype)initWithDictionary:(NSDictionary *)dictionary
httpStatusCode:(HTTPStatusCode)httpStatusCode
{
NSParameterAssert(dictionary);
if (!dictionary) {
return nil;
}

NSMutableDictionary* newDictionary = [NSMutableDictionary dictionary];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather make this check local for the getSource endpoint only. Changing it for all endpoints might break backwards compatibility

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also from the compatibility perspective it makes sense to put this behavior under a setting and disable it by default.

Copy link
Author

@jakobtak jakobtak Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on you to check it only on getSource endpoint.
Sure, I can add another settings. Would you like replaceUnsupportedUnicodeCharacters for the name of a setting?

*/
+ (NSString*) removeInvalidCharsFromString:(NSString*) stringToCheck
{
NSMutableString* fixedUp = [NSMutableString stringWithString:@""];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps something like that would be faster

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case, I was viewing a Korean webpage, so it probably did not contain accents or umlauts. However I will take a look if there is any other builtin methods to make it more simple and fast. Thank you.

@mykola-mokhnach
Copy link

mykola-mokhnach commented Apr 26, 2023

@jakobtak Do you have time to finish the PR?

@jakobtak
Copy link
Author

jakobtak commented Apr 28, 2023

Sure, I've forgot to finish it. I will wrap the this thing up by May 14th.

@mykola-mokhnach
Copy link

Closed in favour of #713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants