@@ -122,7 +122,7 @@ public static IList<T> GetPlatform<T>(this List<PlatformBase> availablePlatforms
122122 b . Os . Equals ( sp . Os , StringComparison . Ordinal ) &&
123123 b . Name . Equals ( sp . Browser , StringComparison . OrdinalIgnoreCase ) ) ;
124124
125- return sp . ScreenResolution == string . Empty
125+ var template = sp . ScreenResolution == string . Empty
126126 ? browser ? . BrowserVersions . FirstOrDefault ( v =>
127127 v . Os . Equals ( sp . Os , StringComparison . Ordinal ) &&
128128 v . BrowserName . Equals ( sp . Browser , StringComparison . OrdinalIgnoreCase ) &&
@@ -132,6 +132,9 @@ public static IList<T> GetPlatform<T>(this List<PlatformBase> availablePlatforms
132132 v . BrowserName . Equals ( sp . Browser , StringComparison . OrdinalIgnoreCase ) &&
133133 v . Name ! . Equals ( sp . BrowserVersion , StringComparison . OrdinalIgnoreCase ) &&
134134 v . ScreenResolutions . Contains ( sp . ScreenResolution ) ) ;
135+
136+ // Return a new instance instead of a reference to prevent state leakage across tests
137+ return template != null ? new BrowserVersion ( template ) : null ;
135138 }
136139
137140 public static BrowserVersion ? FindAndroidBrowser ( this List < PlatformBase > platforms , SaucePlatform sp )
@@ -160,12 +163,15 @@ public static IList<T> GetPlatform<T>(this List<PlatformBase> availablePlatforms
160163 b . Os . Equals ( sp . Os , StringComparison . Ordinal ) &&
161164 b . DeviceName . Equals ( sp . LongName , StringComparison . Ordinal ) ) ;
162165
163- return browser ? . BrowserVersions . Count == 1
166+ var template = browser ? . BrowserVersions . Count == 1
164167 ? browser . BrowserVersions [ 0 ]
165168 : browser ? . BrowserVersions . FirstOrDefault ( v =>
166169 v . Os . Equals ( sp . Os , StringComparison . Ordinal ) &&
167170 v . DeviceName . Equals ( sp . LongName , StringComparison . Ordinal ) &&
168171 v . Name ! . Equals ( sp . BrowserVersion , StringComparison . Ordinal ) ) ;
172+
173+ // Return a new instance instead of a reference to prevent state leakage across tests
174+ return template != null ? new BrowserVersion ( template ) : null ;
169175 }
170176
171177 public static PlatformBase ? FindAndroidPlatform ( this List < PlatformBase > platforms , SaucePlatform sp )
@@ -212,12 +218,15 @@ public static IList<T> GetPlatform<T>(this List<PlatformBase> availablePlatforms
212218 b . PlatformNameForOption . Equals ( sp . Os , StringComparison . Ordinal ) &&
213219 b . DeviceName . Equals ( sp . LongName , StringComparison . Ordinal ) ) ;
214220
215- return browser ? . BrowserVersions . Count == 1
221+ var template = browser ? . BrowserVersions . Count == 1
216222 ? browser . BrowserVersions [ 0 ]
217223 : browser ? . BrowserVersions . FirstOrDefault ( v =>
218224 v . PlatformNameForOption . Equals ( sp . Os , StringComparison . Ordinal ) &&
219225 v . DeviceName . Equals ( sp . LongName , StringComparison . Ordinal ) &&
220226 v . Name ! . Equals ( sp . BrowserVersion , StringComparison . Ordinal ) ) ;
227+
228+ // Return a new instance instead of a reference to prevent state leakage across tests
229+ return template != null ? new BrowserVersion ( template ) : null ;
221230 }
222231
223232 public static PlatformBase ? FindIOSPlatform ( this List < PlatformBase > platforms , SaucePlatform sp )
0 commit comments