Created
November 21, 2022 23:45
-
-
Save NizarETH/40ab5dee2471b095cfb8f34fcb120ee7 to your computer and use it in GitHub Desktop.
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
============================================ | |
Gradle | |
============================================ | |
dependencies { | |
implementation 'androidx.appcompat:appcompat:1.5.1' | |
implementation 'com.google.android.material:material:1.7.0' | |
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | |
testImplementation 'junit:junit:4.13.2' | |
androidTestImplementation 'androidx.test.ext:junit:1.1.4' | |
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' | |
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3' | |
androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
} | |
============================================ | |
New class in Android Test | |
============================================ | |
import android.content.Context; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.support.test.uiautomator.By; | |
import android.support.test.uiautomator.UiDevice; | |
import android.support.test.uiautomator.Until; | |
import androidx.test.ext.junit.runners.AndroidJUnit4; | |
import androidx.test.platform.app.InstrumentationRegistry; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(AndroidJUnit4.class) | |
public class MyPhoneTest { | |
private static final long TIMEOUT = 3000; | |
@Test | |
public void openGoogle() throws Exception { | |
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | |
if(mDevice.isScreenOn()) | |
{ | |
mDevice.setOrientationLeft(); | |
mDevice.openNotification(); | |
mDevice.openQuickSettings(); | |
mDevice.pressBack(); | |
mDevice.pressHome(); | |
} | |
Context context = InstrumentationRegistry.getInstrumentation().getContext(); | |
Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.android.chrome"); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); | |
intent.setData(Uri.parse("https://www.google.com/")); | |
context.startActivity(intent); | |
mDevice.wait(Until.hasObject(By.pkg("com.android.chrome").depth(0)), TIMEOUT); | |
Thread.sleep(4000); | |
mDevice.pressRecentApps(); | |
mDevice.pressBack(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment