This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sourceSets { | |
androidTest { | |
java.srcDir 'src/main/java' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | |
implementation 'androidx.test.ext:junit:1.1.3' | |
implementation 'androidx.test:runner:1.4.0' | |
implementation 'androidx.test.uiautomator:uiautomator:2.2.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'com.android.application' | |
id 'kotlin-android' | |
} | |
android { | |
compileSdkVersion 30 | |
buildToolsVersion "30.0.3" | |
defaultConfig { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.paceli.wifitest"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.paceli.wifitest | |
import android.util.Log | |
import androidx.test.ext.junit.runners.AndroidJUnit4 | |
import org.junit.* | |
import org.junit.runner.RunWith | |
@RunWith(AndroidJUnit4::class) | |
class UiAutomatorOrder { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.paceli.wifitest | |
import androidx.test.ext.junit.runners.AndroidJUnit4 | |
import androidx.test.platform.app.InstrumentationRegistry | |
import androidx.test.uiautomator.UiDevice | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
@RunWith(AndroidJUnit4::class) | |
class WifiTest { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun validateWifi() { | |
// Open apps list by scrolling on home screen | |
val workspace = device.findObject( | |
By.res("com.google.android.apps.nexuslauncher:id/workspace") | |
) | |
workspace.scroll(Direction.DOWN, 1.0f) | |
// Click on Settings icon to launch the app | |
val settings = device.findObject( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
// Obtain an instance of UiObject2 of the text field | |
val ssidField = device.wait(Until.findObject(By.res("com.android.settings:id/ssid")), 2000) | |
// Call the setText method using Kotlin's property access syntax | |
val ssid = "AndroidWifi" | |
ssidField.text = ssid | |
//Click on Save button | |
device.findObject(By.res("android:id/button1").text("Save")).click() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
// Wait up to 2 seconds for the element be displayed on screen | |
val networkAndInternet = device.wait(Until.findObject(By.text("Network & internet")), 2000) | |
networkAndInternet.click() | |
// Click on element with text "Wi‑Fi" | |
val wifi = device.wait(Until.findObject(By.text("Wi‑Fi")), 2000) | |
wifi.click() | |
// Click on element with text "Add network" | |
val addNetwork = device.wait(Until.findObject(By.text("Add network")), 2000) | |
addNetwork.click() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
// BySelector matching the just added Wi-Fi | |
val ssidSelector = By.text(ssid).res("android:id/title") | |
// BySelector matching the connected status | |
val status = By.text("Connected").res("android:id/summary") | |
// BySelector matching on entry of Wi-Fi list with the desired SSID and status | |
val networkEntrySelector = By.clazz(RelativeLayout::class.qualifiedName) | |
.hasChild(ssidSelector) | |
.hasChild(status) |
OlderNewer