<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gleb Tarasov on Medium]]></title>
        <description><![CDATA[Stories by Gleb Tarasov on Medium]]></description>
        <link>https://medium.com/@pilot34?source=rss-7b5881a51002------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*J9nviIvywtYKa5RL.</url>
            <title>Stories by Gleb Tarasov on Medium</title>
            <link>https://medium.com/@pilot34?source=rss-7b5881a51002------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:48:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pilot34/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Measuring mobile apps performance in production]]></title>
            <link>https://medium.com/booking-com-development/measuring-mobile-apps-performance-in-production-726e7e84072f?source=rss-7b5881a51002------2</link>
            <guid isPermaLink="false">https://medium.com/p/726e7e84072f</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[performance-monitoring]]></category>
            <category><![CDATA[app-performance]]></category>
            <category><![CDATA[booking]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Gleb Tarasov]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 14:09:23 GMT</pubDate>
            <atom:updated>2026-12-02T14:37:16.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A turtle is crawling on a mobile phone" src="https://cdn-images-1.medium.com/max/1024/0*jC1mV2lylNzeMJ6v" /></figure><blockquote>“People using your app expect it to perform well. An app that takes a long time to launch, or responds slowly to input, may appear as if it isn’t working or is sluggish. An app that makes a lot of large network requests may increase the user’s data charges and drain the device battery. Any of these behaviors can frustrate users and lead them to uninstall the app.”</blockquote><blockquote><a href="https://developer.apple.com/documentation/xcode/improving-your-app-s-performance"><em>Apple Documentation</em></a></blockquote><p><strong>UPD:</strong> I gave a talk at <em>devCon 2026</em> about the same topic. You can get the similar info in the video format <a href="https://www.youtube.com/watch?v=ZSeHXBmWpK8">here</a>.</p><p>App performance is an integral part of the user experience. An app that’s prone to freezing or takes ages to launch won’t satisfy our customers. If the waiting time to load search results or the hotel details screen is too long, it could detract from the excitement of planning upcoming vacations. This is something we would definitely prefer to avoid. However every new feature could slightly degrade app performance and certain changes might have a greater impact, which can get out of control.</p><p>The key aspect of mitigating performance issues in mobile apps is proper monitoring; otherwise, any effort to improve or preserve the performance would turn into jumping in at the deep end.</p><h3>A brief history of the App Performance team</h3><p>At Booking.com we’ve been monitoring app performance metrics for quite some time. For instance, the first iOS startup time metric was introduced in 2016. Around 2019 the team responsible for monitoring &amp; improving the performance was created.</p><p>By 2021, the team realized that the existing setup for performance monitoring was quite obsolete, unreliable and didn’t fully fit our requirements, so it needed a revision.</p><p>While addressing the functional improvements in metrics, we also decided to rewrite the performance libraries completely, simultaneously transitioning from the older Objective-C/Java to the modern Swift/Kotlin languages. Throughout this process, we designed our libraries to be fully independent of other Booking infrastructures, injecting external dependencies like experimentation, storage, and networking.</p><h3>Why not use existing third-party tools</h3><p>There’s no shortage of free or paid tools to monitor app performance. Apple and Google offer some out-of-the-box monitoring solutions, and there are a few big third-party players such as <a href="https://firebase.google.com/docs/perf-mon">Firebase Performance</a>.</p><p>However, our monitoring tool had three primary requirements, all of which were related to integrating with the Booking infrastructure and covering specifics of our development culture:</p><ul><li><strong>Experimentation: </strong>Given the strong <a href="https://booking.ai/understanding-mechanisms-of-change-in-online-experiments-at-booking-com-629201ec74ee">experimentation</a> culture in the company, the most critical requirement was to ensure reliable and simple integration with our internal experimentation infrastructure.</li><li><strong>Alerting:</strong> We require a flexible alerting/SLA system that can promptly notify different teams about performance degradations. Metrics should come from real devices as quickly as possible to ensure timely alerting.</li><li><strong>Flexibility:</strong> We wanted the option to customize existing metrics defined by Apple &amp; Google. For instance, on iOS, we aim to differentiate between app startup time and launch time of the first screen. This means we end startup time measurements sooner than Apple’s default monitoring system does.</li></ul><p>Sadly, no third-party solutions met even two of our three criteria. So, we needed to implement our own solution.</p><h3>What we measure</h3><p>After recognizing the need for performance monitoring, we had to determine the metrics to track. Every metric should address a user pain point. We identified two primary user concerns: wait time and interface smoothness. This led us to focus on three primary metrics:</p><ul><li>App startup time</li><li>Screen time to interactive (TTI)</li><li>Frame rendering performance</li></ul><p>The core business of our company is to provide fast and reliable search and booking services. So we have gathered enough data from real users to validate that significant degradation of these metrics often impacts the conversion, and almost always negatively affects user engagement metrics.</p><h3>App startup time</h3><p>The App Startup Time metric measures the time in milliseconds (ms) from the user tapping the app icon on their Home screen till the app draws its first frame.</p><figure><img alt="Startup time diagram" src="https://cdn-images-1.medium.com/max/1024/0*rtXZI_AjnzZOGC7j" /></figure><p>Both platforms also differentiate between “cold” and “warm” app starts, but our main focus was to improve the “cold” launches, which is when the system cannot benefit from the app state previously cached in memory. That’s because the “warm” starts mostly depend on the performance of specific screens opened first when a user returns to the app (and as you will see in the next section we measure this metric separately anyway).</p><p>More details &amp; official recommendations regarding app startup process for every platform you could find in official developer documentations (<a href="https://developer.apple.com/documentation/xcode/reducing-your-app-s-launch-time">iOS</a> &amp; <a href="https://developer.android.com/topic/performance/vitals/launch-time">Android</a>).</p><h3>Time to Interactive (TTI)</h3><p>Time to Interactive (TTI) is the time in milliseconds (ms) spent from the screen’s creation start until the first frame of meaningful content is rendered, ensuring that:</p><ul><li>All internal setup is ready</li><li>UI is laid out and rendered</li><li>Most important data has arrived and is shown to the user</li><li>Main thread is ready to process incoming events</li></ul><p>TTI always includes native app performance, and for several particular screens, it may also depend on network or storage performance. This metric allows us to monitor how fast customers can actually start using the screen for its main purpose.</p><p>Initially, this metric <a href="https://web.dev/interactive/">was defined by Google for web-development</a> but we’ve found it very useful and perfectly suitable for mobile apps as well.</p><p>To investigate degradations in TTI, we need to understand the reasons behind them. For this purpose, we use supportive metrics. We monitor the wall-clock time and the latency of every network request related to screen loading, which helps us identify degradations caused by the backend. For screens that involve heavy read/write storage operations, it also makes sense to monitor storage performance separately.</p><p>Additionally, we use the Time To First Render metric to pinpoint degradations caused by screen creation and rendering (see the next section).</p><h4>Time To First Render (TTFR)</h4><p>Time To First Render (TTFR) is the time in milliseconds (ms) spent from the screen’s creation start until the screen renders its first frame.</p><p>It starts at the same time as the general TTI measurement but may stop earlier. In the most common case, the screen should be ready to be drawn as soon as possible, but it shouldn’t necessarily show meaningful content immediately. Usually, the screen can show some “progress indicator” and do some heavy initializations in the background. We stop TTFR tracking once the very first frame is drawn, so the metric is pretty close to measuring the screen’s creation time. It allows us to prevent the UI thread from freezing during creation, which leads to a better user experience.</p><p>This metric directly impacts TTI and may impact Rendering Performance as well.</p><figure><img alt="TTI diagram" src="https://cdn-images-1.medium.com/max/1024/0*k_QHSr_dKbNTlGP9" /></figure><h3>Rendering performance</h3><p>To ensure that a user’s interaction with an app is smooth, the app should render frames in under 16 ms to achieve 60 frames per second (note: on many modern devices, the target might be set to 90 or 120 fps due to higher display frame rates, but we will refer to 60 fps in this article). If the frame rendering time exceeds 16 ms, then the system is forced to skip frames and the user will perceive stuttering in the app.</p><p>Let’s try to visualize how the app renders frames on the timeline:</p><figure><img alt="Freezes duration diagram" src="https://cdn-images-1.medium.com/max/1024/1*plJgZwORrEXHm6scd4hGYA.png" /></figure><p>There are 2 main factors that have an impact on how bad the rendering performance might be:</p><ul><li><strong>Freeze duration:</strong> Identifies how long it takes to render a single slow frame. The longer it takes, the more noticeable performance problem is (e.g. frame that renders for 500ms looks much worse than the frame that renders for 32ms).</li><li><strong>Freezes count or freeze frequency:</strong> Identifies how many or how often users experience slow frames. The more often users experience the same slow frame with the same freeze duration the worse it looks.</li></ul><p>Considering these 2 factors we can come up with the definition for the metric which represents the rendering performance quite accurately:</p><ul><li><strong>Freeze Time:</strong> The total time of UI freezing due to the rendering of slow frames per screen (or app) session.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fj8ooBqfNpULEHwva6fG8w.png" /></figure><p>In the illustration above we see 6 frames: 3 frames are good and 3 frames have freezes. That means that 3 good frames were rendered within 16ms and 3 other frames have freezes of different durations. We calculate freeze duration as a difference between the actual frame duration and 16ms of the target frame duration. To calculate total freeze time we need to summarize the durations of all freezes that happen on the screen.</p><p>Freeze Time can be the same with different patterns: 1 freeze with 1000ms, 100 freezes with 10ms. Also, freeze time can increase without any additional change just by increased session duration (e.g. when every item of the scrollable list generates some slow frames and the user starts to scroll more it leads to a higher total freeze time).</p><p>To catch such situations we are also using 2 additional metrics:</p><ul><li><strong>Freeze Count:</strong> The total count of slow frames (slower than 16ms) during a screen session. To see if the pattern of freezes changes.</li><li><strong>Session Duration:</strong> The screen session duration. To see if session duration changed which might cause freeze time changes.</li></ul><h4>Rationale for choosing the Freeze Time metric</h4><p>Both Google and Apple offer metrics for assessing rendering performance. Initially, we adopted a method <a href="https://firebase.google.com/docs/perf-mon/screen-traces?platform=android">implemented by Firebase</a> for our rendering performance monitoring, which involved tracking <strong>slow frames</strong> (&gt;16ms to render) and<strong> frozen frames</strong> (&gt;700ms). However, we discovered that these metrics did not adequately capture rendering performance degradation.</p><p>For instance, consider a scenario where views in a list are already slow, requiring 20ms for rendering. If the rendering time increases to 300ms, the metrics would still report one slow frame per view without any frozen frames, failing to indicate a significant deterioration in rendering time.</p><p>Moreover, there is an inconsistency in how performance changes are reflected. A view’s rendering time increasing from 15ms to 20ms is recorded as the same metric change as an increase from 15ms to 300ms, which does not accurately represent the severity of the slowdown.</p><p>Apple’s “Hang rate” metric, which is calculated as seconds of hang time per hour, appeared to be more in line with what we needed. It resembles our Freeze Time metric but is normalized by dividing the total freeze time by the session duration. However, this normalization caused the metric to become overly sensitive to changes in user behavior.</p><p>For instance, if a product feature causes users to spend more time scrolling through a slow list, the Hang rate may show an improvement because the session duration increased, even though the user experience has degraded due to more freezes.</p><p>After encountering various scenarios where the relative metric did not provide a clear picture of performance, we decided to use an absolute metric instead. This allows us to measure rendering performance more accurately, not just for the entire application but for each screen session, without the results being skewed by user behavior or session length.</p><p>The absolute metric has certain limitations too. For instance, we can take the same example: if a product feature results in users scrolling through a slow list more frequently, the rendering metric would worsen even though there hasn’t been a technical decline in performance. However, incorporating a supplementary metric Session Duration allows us to manage these situations effectively.</p><p>The main idea behind this is that we consider any increase in Freeze Time as a negative performance change, regardless of the reason (though ideally, the user shouldn’t see any freezes at all). Of course, it is important to react to new performance issues caused by a new feature, but it is also important to detect the old screen producing more freezes because users start to interact with it more actively.</p><h3>Show me the code!</h3><figure><img alt="PerformanceSuite logo: a mix of a turtle and a swift" src="https://cdn-images-1.medium.com/max/393/0*dwyT-iXhB9o65ocv" /></figure><p>Wrapping up all the theoretical knowledge and clear metric definitions we finally can implement the working solution for collecting these metrics. We’ve recently open-sourced our performance tracking libraries for both platforms, which you can find on GitHub:</p><ul><li><a href="https://github.com/bookingcom/perfsuite-ios">PerformanceSuite for iOS</a></li><li><a href="https://github.com/bookingcom/perfsuite-android">PerformanceSuite for Android</a></li></ul><p>These light-weight libraries help to gather aforementioned metrics and allows you to report them to any analytics system. We are actively working on further improvements and new features (e.g. terminations monitoring), however, it is already used in the main Booking app on both platforms. The iOS library is also used in our app <a href="https://apps.apple.com/app/pulse-voor-booking-com/id992795726"><em>Pulse</em></a> for the property owners and in the <a href="https://apps.apple.com/app/agoda-book-hotels-and-flights/id440676901"><em>Agoda</em></a> app from our sister company.</p><p>Feel free to try it out, leave feedback, or even better, contribute!</p><p><a href="https://medium.com/u/13fbd72701d9">Vadim Chepovsky</a> and <a href="https://medium.com/u/7b5881a51002">Gleb Tarasov</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=726e7e84072f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/booking-com-development/measuring-mobile-apps-performance-in-production-726e7e84072f">Measuring mobile apps performance in production</a> was originally published in <a href="https://medium.com/booking-com-development">Booking.com Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Xcode measures app launch time]]></title>
            <link>https://pilot34.medium.com/how-xcode-measures-app-launch-time-b5a66bd07c8c?source=rss-7b5881a51002------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5a66bd07c8c</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[startuptime]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[app-launch-time]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Gleb Tarasov]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 16:30:07 GMT</pubDate>
            <atom:updated>2021-01-21T16:31:33.061Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*9DSi33k9Uxe3Rh2pujQxBg.png" /></figure><p>Apple recently added Launch time metric in Xcode organizer and ability to measure launch time in UI tests (<em>XCTApplicationLaunchMetric</em>).</p><p>To be able to optimize this metric we should understand, how is it measured. Which code is included and which is not.</p><p>Apple documentation <a href="https://developer.apple.com/documentation/xcode/improving_your_app_s_performance/reducing_your_app_s_launch_time">says</a>:</p><blockquote>Launch Time pane in Xcode shows the amount of milliseconds between the user tapping your icon to launch the app, and the time the system drawing something other than the launch screen.</blockquote><p>To understand what is included there I created a simple app where I have <em>AppDelegate</em>, <em>ViewController</em> and <em>View</em> objects, <em>main()</em> function in <em>main.m</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fc37fc4814f5183442851a0513bd298/href">https://medium.com/media/5fc37fc4814f5183442851a0513bd298/href</a></iframe><p>This is what we see in output:</p><blockquote>AppDelegate.init<br>AppDelegate.didFinishLaunchingWithOptions<br>ViewController.init<br>View.init<br>ViewController.viewDidLoad<br>View.didMoveToWindow<br>ViewController.viewWillAppear<br>View.willMoveToWindow<br>View.didMoveToWindow<br>AppDelegate.applicationDidBecomeActive<br>ViewController.viewWillLayoutSubviews<br>View.layoutSubviews<br>ViewController.viewDidLayoutSubviews</blockquote><blockquote>→ → → → XCTApplicationLaunchMetric<em> stops measurement here</em></blockquote><blockquote>ViewController.viewDidAppear</blockquote><p>I created simple UI test and did measurements by adding <em>Thread.sleep </em>to different methods.</p><pre>func testLaunchPerformance() throws {</pre><pre>   measure(metrics: [XCTApplicationLaunchMetric()]) {</pre><pre>       XCUIApplication().launch()</pre><pre>   }</pre><pre>}</pre><p>It turned out, that everything except the last line (`ViewController.viewDidAppear`) is included into <em>XCTApplicationLaunchMetric.</em></p><p>Good to know, that of course <em>main() </em>is also included into the launch time. But also all Objective-C +(void)load methods for your binary and all linked frameworks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5a66bd07c8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UIView with manual dynamic height inside auto-layout hierarchy]]></title>
            <link>https://pilot34.medium.com/uiview-with-manual-dynamic-height-inside-auto-layout-hierarchy-604b69803de3?source=rss-7b5881a51002------2</link>
            <guid isPermaLink="false">https://medium.com/p/604b69803de3</guid>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[constraints]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[intrinsic-content-size]]></category>
            <dc:creator><![CDATA[Gleb Tarasov]]></dc:creator>
            <pubDate>Sat, 23 May 2020 22:35:20 GMT</pubDate>
            <atom:updated>2020-05-24T13:58:49.072Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes you need to implement a manual layout for the view, that can be used inside auto-layouted hierarchy. In my case I needed a flow layout inside a simple view, without UICollectionView .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*GjcGU5ebb8GHaigbos8PZw.png" /></figure><p>This view should have intrinsicContentSize so it can work correctly inside some stack views or somewhere else with layout constraints.</p><p>But the problem is that you cannot have intrinsicContentSize that depends on current width of the view.</p><p>To fix that we can add local variable preferredMaxLayoutWidth the same as we have in UILabel . And we will update it inside layoutSubviews :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29710bd53d07f0c557a39ee1855bdb97/href">https://medium.com/media/29710bd53d07f0c557a39ee1855bdb97/href</a></iframe><p>The only problem with this implementation, our view will not return correct size when method systemLayoutSizeFitting(size) will by called, because after this call our view will only be called with intrinsicContentSize method. So we cannot know which size was passed to systemLayoutSizeFitting and we will not be able to calculate appropriate width.</p><p>Solution that can be used a bit hacky. You need to inherit UILabel and override textRect(forBounds) method. This method will be called even after systemLayoutSizeFitting so we can really calculate intrinsicContentSize depends on the passed width.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfbb2a2690c5527ee3053ebe928cfc4b/href">https://medium.com/media/dfbb2a2690c5527ee3053ebe928cfc4b/href</a></iframe><p>That’s all. And don’t forget to call invalidateIntrinsicContentSize() when your view internal data changed and you need to recalculate your textRect(forBounds) .</p><p><a href="https://gist.github.com/pilot34/d8b2241f8d59526703ea758572e8b102">Full example can be bound here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=604b69803de3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Store your git hooks in a repository]]></title>
            <link>https://pilot34.medium.com/store-your-git-hooks-in-a-repository-2de1d319848c?source=rss-7b5881a51002------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de1d319848c</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[pre-commit]]></category>
            <dc:creator><![CDATA[Gleb Tarasov]]></dc:creator>
            <pubDate>Mon, 06 Apr 2020 19:38:57 GMT</pubDate>
            <atom:updated>2020-09-02T09:20:47.195Z</atom:updated>
            <content:encoded><![CDATA[<h3>Store your git hooks in a repository and setup them for all the developers</h3><p>Usually in the company you have some guidelines which git hooks developer should set. But I realised recently, that you can setup your hooks in the repository so every developer will have those hooks automatically. And every change will be picked automatically also.</p><p>As the example here I’m setting up the pre-commit hook, but you can set any type with the same trick.</p><ol><li>Commit your hooks to your repo. For example, to the hooks folder. Be sure, that your script has permission for execution. Do chmod 755 hooks/pre-commit before commit.</li><li>Create your global .gitconfig file in the repo. Execute this command:</li></ol><pre>git config -f .gitconfig core.hooksPath hooks</pre><p>3. Commit your new .gitconfig file to your repo.</p><p>4. Every user will still need to run this command once after repository checkout:</p><pre>git config --local include.path ../.gitconfig</pre><p>And that’s all. If some developer wants to have custom hook, she can overridecore.hooksPath locally.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de1d319848c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Work with SFSafariViewController or WKWebView in Xcode UI Tests]]></title>
            <link>https://pilot34.medium.com/work-with-sfsafariviewcontroller-or-wkwebview-in-xcode-ui-tests-8b14fd281a1f?source=rss-7b5881a51002------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b14fd281a1f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ui-testing]]></category>
            <category><![CDATA[xctest]]></category>
            <dc:creator><![CDATA[Gleb Tarasov]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 09:57:20 GMT</pubDate>
            <atom:updated>2018-12-14T23:01:40.475Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: check comments to this article before reading. </em><a href="https://medium.com/u/7cf9b801013"><em>Ilya Puchka</em></a><em> found the better solution as a workaround.</em></p><p>You can note, that Xcode 9.3 crashes when you record UI Test with its recording tool and tap on SFSafariViewController content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3lpmnFKvYqQuFW3MFRq5A.gif" /><figcaption>Crash in Xcode after tap on SFSafariViewController</figcaption></figure><pre>caught &quot;NSInternalInconsistencyException&quot;, &quot;Invalid parameter not satisfying: [descendant _isDescendantOfElement:self]&quot;</pre><p>That occurs because of <a href="http://www.openradar.me/36788196">bug in Xcode</a> and is very annoying. Because we need to interract with web view, for example, if we want to test Facebook or other social login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sSY87SO-gPd_8Z7PX40k4g.png" /></figure><p>It’s interesting, that during debug, you can debugPrint all buttons and fields of a web view without any problem. But you cannot tap on button or typeText into text field because of NSInternalInconsistencyException.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BCzUgOAtxU_7QspfD8rvA.png" /></figure><p>For successful testing I needed few things from web view elements:</p><ul><li>check if element exists</li><li>wait for element to appear</li><li>tap on button</li><li>clear text in text field</li><li>type text into text field</li></ul><p>Having in mind, that we can debugPrint elements, we can try this crazy solution: parse debugDescription of element, take its frame from that and tap XCUIApplication by coordinate. Lets code that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c380097ee8a8464ba76887d2e65e6a4/href">https://medium.com/media/3c380097ee8a8464ba76887d2e65e6a4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4694f09979d6e38f70b3cc4e4ae3425/href">https://medium.com/media/c4694f09979d6e38f70b3cc4e4ae3425/href</a></iframe><p>The next problem is that we cannot typeText into text field. But that cannot stop us, right? We can tap on location, so we can paste a text via copy/paste menu. Also we can clear current text in a text field with <strong>“Select All”</strong> and <strong>“Cut”</strong>.</p><p>Let’s try.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12127c7ad761216f3b8c66841ea25bb9/href">https://medium.com/media/12127c7ad761216f3b8c66841ea25bb9/href</a></iframe><p>That’s all. Now we can test many things inside the web views. That should work for SFSafariViewController and, I hope, with WKWebView or UIWebView (I didn’t test that).</p><p>All code in one file: <a href="https://gist.github.com/pilot34/09d692f74d4052670f3bae77dd745889">https://gist.github.com/pilot34/09d692f74d4052670f3bae77dd745889</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b14fd281a1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>