1717#import " FBXMLGenerationOptions.h"
1818#import " FBXCElementSnapshotWrapper+Helpers.h"
1919#import " NSString+FBXMLSafeString.h"
20+ #import " XCUIApplication.h"
2021#import " XCUIElement.h"
2122#import " XCUIElement+FBCaching.h"
2223#import " XCUIElement+FBUtilities.h"
2324#import " XCUIElement+FBWebDriverAttributes.h"
2425#import " XCTestPrivateSymbols.h"
2526#import " FBElementHelpers.h"
27+ #import " FBXCAXClientProxy.h"
28+ #import " FBXCAccessibilityElement.h"
2629
2730
2831@interface FBElementAttribute : NSObject
@@ -33,6 +36,7 @@ + (nonnull NSString *)name;
3336+ (nullable NSString *)valueForElement : (id <FBElement>)element ;
3437
3538+ (int )recordWithWriter : (xmlTextWriterPtr)writer forElement : (id <FBElement>)element ;
39+ + (int )recordWithWriter : (xmlTextWriterPtr)writer forValue : (nullable NSString *)value ;
3640
3741+ (NSArray <Class> *)supportedAttributes ;
3842
@@ -98,7 +102,13 @@ @interface FBInternalIndexAttribute : FBElementAttribute
98102
99103@property (nonatomic , nonnull , readonly ) NSString * indexValue;
100104
101- + (int )recordWithWriter : (xmlTextWriterPtr)writer forValue : (NSString *)value ;
105+ @end
106+
107+ @interface FBApplicationBundleIdAttribute : FBElementAttribute
108+
109+ @end
110+
111+ @interface FBApplicationPidAttribute : FBElementAttribute
102112
103113@end
104114
@@ -472,6 +482,27 @@ + (int)recordElementAttributes:(xmlTextWriterPtr)writer
472482 // index path is the special case
473483 return [FBInternalIndexAttribute recordWithWriter: writer forValue: indexPath];
474484 }
485+ if (element.elementType == XCUIElementTypeApplication) {
486+ // only record process identifier and bundle identifier for the application element
487+ int pid = [element.accessibilityElement processIdentifier ];
488+ if (pid > 0 ) {
489+ int rc = [FBApplicationPidAttribute recordWithWriter: writer
490+ forValue: [NSString stringWithFormat: @" %d " , pid]];
491+ if (rc < 0 ) {
492+ return rc;
493+ }
494+ XCUIApplication *app = [[FBXCAXClientProxy sharedClient ]
495+ monitoredApplicationWithProcessIdentifier: pid];
496+ NSString *bundleID = [app bundleID ];
497+ if (nil != bundleID) {
498+ rc = [FBApplicationBundleIdAttribute recordWithWriter: writer
499+ forValue: bundleID];
500+ if (rc < 0 ) {
501+ return rc;
502+ }
503+ }
504+ }
505+ }
475506 return 0 ;
476507}
477508
@@ -585,6 +616,11 @@ + (NSString *)valueForElement:(id<FBElement>)element
585616+ (int )recordWithWriter : (xmlTextWriterPtr)writer forElement : (id <FBElement>)element
586617{
587618 NSString *value = [self valueForElement: element];
619+ return [self recordWithWriter: writer forValue: value];
620+ }
621+
622+ + (int )recordWithWriter : (xmlTextWriterPtr)writer forValue : (nullable NSString *)value
623+ {
588624 if (nil == value) {
589625 // Skip the attribute if the value equals to nil
590626 return 0 ;
@@ -830,22 +866,25 @@ + (NSString *)name
830866 return kXMLIndexPathKey ;
831867}
832868
833- + (int )recordWithWriter : (xmlTextWriterPtr)writer forValue : (NSString *)value
869+ @end
870+
871+ @implementation FBApplicationBundleIdAttribute : FBElementAttribute
872+
873+ + (NSString *)name
834874{
835- if (nil == value) {
836- // Skip the attribute if the value equals to nil
837- return 0 ;
838- }
839- int rc = xmlTextWriterWriteAttribute (writer,
840- (xmlChar *)[[FBXPath safeXmlStringWithString: [self name ]] UTF8String ],
841- (xmlChar *)[[FBXPath safeXmlStringWithString: value] UTF8String ]);
842- if (rc < 0 ) {
843- [FBLogger logFmt: @" Failed to invoke libxml2>xmlTextWriterWriteAttribute(%@ ='%@ '). Error code: %d " , [self name ], value, rc];
844- }
845- return rc;
875+ return @" bundleId" ;
846876}
877+
847878@end
848879
880+ @implementation FBApplicationPidAttribute : FBElementAttribute
881+
882+ + (NSString *)name
883+ {
884+ return @" processId" ;
885+ }
886+
887+ @end
849888
850889@implementation FBPlaceholderValueAttribute
851890
0 commit comments