Skip to content

Instantly share code, notes, and snippets.

@LivPNavusoft
Created February 14, 2024 15:50
Show Gist options
  • Save LivPNavusoft/a190821ffeab12430f651a02727e9b0a to your computer and use it in GitHub Desktop.
Save LivPNavusoft/a190821ffeab12430f651a02727e9b0a to your computer and use it in GitHub Desktop.
AppiumAndroidTest
import io.appium.java_client.AppiumBy
import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.remote.options.BaseOptions
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.net.MalformedURLException
import java.net.URL
public class AuthTest {
var driver: AndroidDriver? = null
@Before
fun setUp() {
var options = BaseOptions()
.amend("platformName", "Android")
.amend("appium:automationName", "UiAutomator2")
.amend("appium:ensureWebviewsHavePages", true)
.amend("appium:nativeWebScreenshot", true)
.amend("appium:newCommandTimeout", 3600)
.amend("appium:connectHardwareKeyboard", true);
val url = getUrl()
if (url != null) {
driver = AndroidDriver(url, options);
}
}
private fun getUrl(): URL? {
try {
return URL("http://127.0.0.1:4723");
} catch (e: MalformedURLException) {
e.printStackTrace();
}
return null
}
@Test
fun sampleTest() {
if (driver != null) {
var loginButton = driver!!.findElement(AppiumBy.xpath("//androidx.compose.ui.platform.ComposeView/android.view.View/android.view.View/android.view.View[1]/android.widget.Button"))
loginButton.click()
}
}
@After
fun tearDown() {
driver?.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment