-
Notifications
You must be signed in to change notification settings - Fork 0
/
Results.kts
62 lines (47 loc) · 1.5 KB
/
Results.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import io.appium.java_client.*
import io.appium.java_client.touch.*
import io.appium.java_client.touch.offset.*
import io.appium.java_client.android.*
import org.openqa.selenium.*
import org.openqa.selenium.support.ui.*
class Screen(val app: AppiumDriver<MobileElement>) {
val swipes = 15
val x1 = app.manage().window().getSize().getWidth() / 2
val y1 = (app.manage().window().getSize().getHeight() * 0.9).toInt()
val bottom = PointOption.point(x1, y1)
val x2 = x1
val y2 = (app.manage().window().getSize().getHeight() * 0.2).toInt()
val top = PointOption.point(x2, y2)
val twoSeconds = java.time.Duration.ofSeconds(2)
val delay = WaitOptions.waitOptions(twoSeconds)
fun scrollTo(result: String): Screen {
for (i in 1..swipes) {
AndroidTouchAction(app)
.press(bottom)
.waitAction(delay)
.moveTo(top)
.release()
.perform()
val resultCard = try {
app.findElement(MobileBy.AndroidUIAutomator("""text("$result")"""))
}
catch (e: NoSuchElementException) {
null
}
if (resultCard != null) {
break
}
}
return this
}
fun choose(result: String): Package.Screen {
val resultCard = app.findElement(MobileBy.AndroidUIAutomator("""text("$result")"""))
resultCard.click()
WebDriverWait(app, 5).until(
ExpectedConditions.visibilityOfElementLocated(
MobileBy.id("com.rascarlo.aurdroid:id/info_result_body_include")
)
)
return Package.Screen(app)
}
}