@@ -12,8 +12,9 @@ import com.example.superapp.utils.waitFor
1212import com.superwall.sdk.Superwall
1313import com.superwall.sdk.analytics.superwall.SuperwallEvent
1414import com.superwall.superapp.test.UITestHandler
15+ import kotlinx.coroutines.CoroutineScope
1516import kotlinx.coroutines.Dispatchers
16- import kotlinx.coroutines.launch
17+ import kotlinx.coroutines.async
1718import org.junit.Rule
1819import org.junit.Test
1920import org.junit.runner.RunWith
@@ -29,6 +30,8 @@ class FlowScreenshotTestExecutor {
2930 imageComparator = CustomComparator (),
3031 )
3132
33+ val mainScope = CoroutineScope (Dispatchers .Main )
34+
3235 @Test
3336 fun test_paywall_reappers_with_video () =
3437 with (dropshots) {
@@ -37,7 +40,7 @@ class FlowScreenshotTestExecutor {
3740 it.waitFor { it is SuperwallEvent .PaywallWebviewLoadComplete }
3841 awaitUntilShimmerDisappears()
3942 awaitUntilWebviewAppears()
40- delayFor(100 .milliseconds)
43+ delayFor(500 .milliseconds)
4144 }
4245 step(" second_paywall" ) {
4346 awaitUntilWebviewAppears()
@@ -56,23 +59,33 @@ class FlowScreenshotTestExecutor {
5659 awaitUntilWebviewAppears()
5760 delayFor(500 .milliseconds)
5861 // We scroll a bit to display the button
59- Superwall .instance.paywallViewController
60- ?.webView
61- ?.scrollBy(0 , 300 )
62+ mainScope
63+ .async {
64+ Superwall .instance.paywallView
65+ ?.webView
66+ ?.scrollBy(0 , 300 ) ? : kotlin.run {
67+ throw IllegalStateException (" No viewcontroller found" )
68+ }
69+ }.await()
6270 // We delay a bit to ensure the button is visible
6371 delayFor(100 .milliseconds)
6472 // We scroll back to the top
65- Superwall .instance.paywallViewController
66- ?.webView
67- ?.scrollTo(0 , 0 )
73+ mainScope
74+ .async {
75+ Superwall .instance.paywallView
76+ ?.webView
77+ ?.scrollTo(0 , 0 ) ? : kotlin.run {
78+ throw IllegalStateException (" No viewcontroller found" )
79+ }
80+ }.await()
6881 // We delay a bit to ensure scroll has finished
6982 delayFor(1 .seconds)
7083 }
7184 }
7285 }
7386
7487 @Test
75- fun test_paywall_reappers_after_dismissing () =
88+ fun test_paywall_reappears_after_dismissing () =
7689 with (dropshots) {
7790 screenshotFlow(UITestHandler .test11Info) {
7891 step {
@@ -86,7 +99,6 @@ class FlowScreenshotTestExecutor {
8699 delayFor(1 .seconds)
87100 }
88101 step {
89- it.waitFor { it is SuperwallEvent .PaywallClose }
90102 it.waitFor { it is SuperwallEvent .PaywallOpen }
91103 awaitUntilWebviewAppears()
92104 delayFor(1 .seconds)
@@ -100,7 +112,8 @@ class FlowScreenshotTestExecutor {
100112 screenshotFlow(UITestHandler .test34Info) {
101113 step(" " ) {
102114 it.waitFor { it is SuperwallEvent .PaywallWebviewLoadComplete }
103- awaitUntilShimmerDisappears() || awaitUntilWebviewAppears()
115+ awaitUntilShimmerDisappears()
116+ awaitUntilWebviewAppears()
104117 }
105118 step {
106119 it.waitFor { it is SuperwallEvent .Reset }
@@ -117,27 +130,36 @@ class FlowScreenshotTestExecutor {
117130 it.waitFor { it is SuperwallEvent .PaywallWebviewLoadComplete }
118131 awaitUntilShimmerDisappears()
119132 awaitUntilWebviewAppears()
120- delayFor(500 .milliseconds)
121- launch(Dispatchers .Main ) {
122- // We scroll a bit to display the button
123- Superwall .instance.paywallViewController
124- ?.webView
125- ?.scrollBy(0 , 300 )
126- }
133+ delayFor(100 .milliseconds)
134+ mainScope
135+ .async {
136+ // We scroll a bit to display the button
137+ Superwall .instance.paywallView
138+ ?.webView
139+ ?.apply {
140+ // Disable the scrollbar for the test
141+ // so its not visible in screenshots
142+ isVerticalScrollBarEnabled = false
143+ scrollTo(0 , 300 )
144+ }
145+ }.await()
127146 // We delay a bit to ensure the button is visible
128147 delayFor(100 .milliseconds)
129148 // We scroll back to the top
130- launch(Dispatchers .Main ) {
131- Superwall .instance.paywallViewController
132- ?.webView
133- ?.scrollTo(0 , 0 )
134- }
149+ mainScope
150+ .async {
151+ Superwall .instance.paywallView
152+ ?.webView
153+ ?.apply {
154+ scrollTo(0 , 0 )
155+ }
156+ }.await()
135157 // We delay a bit to ensure scroll has finished
136- delayFor(1 .seconds )
158+ delayFor(500 .milliseconds )
137159 }
138160
139161 step {
140- it.waitFor { it is SuperwallEvent . PaywallClose }
162+ delayFor( 10 .seconds)
141163 }
142164 }
143165 }
0 commit comments