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
private fun getCurrentWifiSsid(): String? { | |
val context = InstrumentationRegistry.getInstrumentation().context | |
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager | |
val wifiInfo = wifiManager.connectionInfo | |
// The SSID is quoted, then we need to remove quotes | |
return wifiInfo.ssid?.removeSurrounding("\"") | |
} |
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
@After | |
fun tearDown() { | |
// Press Home key after running the test | |
device.pressHome() | |
} |
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
@Before | |
fun setUp() { | |
// Press Home key before running the test | |
device.pressHome() | |
} |
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
// ... | |
// 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