Giter VIP home page Giter VIP logo

Comments (11)

brettchabot avatar brettchabot commented on July 18, 2024 2

Oh I just noticed in your description "2-After clicking on this button, the app should be restarted (Expected Result)'. You cannot restart the app from within an instrumented test, because that will kill the process the test is running in.

If you need to do this you might want to look into using UiAutomator, and setting up your tests so they run in a different process than the application under test.

from testing-samples.

brettchabot avatar brettchabot commented on July 18, 2024

Can you provide a complete sample and/or a logcat? The list of dependencies look a bit strange with a mixture of very old and new dependencies. eg The ' androidTestImplementation 'com.android.support.test:rules:1.0.2'' especially seems wrong

from testing-samples.

MohamedGaberM avatar MohamedGaberM commented on July 18, 2024

Can you provide a complete sample and/or a logcat? The list of dependencies look a bit strange with a mixture of very old and new dependencies. eg The ' androidTestImplementation 'com.android.support.test:rules:1.0.2'' especially seems wrong

This is the complete very simple test case
and no problem with ' androidTestImplementation 'com.android.support.test:rules:1.0.2'' especially seems wrong
i remove it and the same error happen

@RunWith(AndroidJUnit4.class)
public class SplashActivityTest{

    @Rule
    public ActivityScenarioRule<SplashActivity> mActivityScenarioRule =
            new ActivityScenarioRule<>(SplashActivity.class);

    @Test
    public void splashActivityTest(){

        onView(withId(R.id.preliveButton)).perform(click());

from testing-samples.

brettchabot avatar brettchabot commented on July 18, 2024

Sorry but without a full sample or logcat our ability to help is going to be limited. I tried copying over your list of dependencies into a simple sample project and it worked fine. You can use one of http://github/android/testing-samples as a base

from testing-samples.

MohamedGaberM avatar MohamedGaberM commented on July 18, 2024

Collaborator

but this is a hard restart, this button should be clicked at the start of the process to can select the environment
and after clicking, the app will hard restart.
so can't handle this case with espresso?

from testing-samples.

MohamedGaberM avatar MohamedGaberM commented on July 18, 2024

Oh I just noticed in your description "2-After clicking on this button, the app should be restarted (Expected Result)'. You cannot restart the app from within an instrumented test, because that will kill the process the test is running in.

If you need to do this you might want to look into using UiAutomator, and setting up your tests so they run in a different process than the application under test.

and how can i use UiAutomator to can continue my test cases after restarting app?

from testing-samples.

brettchabot avatar brettchabot commented on July 18, 2024

Espresso will wait for the app to be idle after the click is sent, so I strongly suspect this case cannot be handled in espresso. How does the code under test restart the app?

For UiAutomator, check out https://github.com/android/testing-samples/tree/main/ui/uiautomator/BasicSample. You'll likely need to adjust the targetProcess here

<instrumentation android:targetPackage="com.example.android.testing.uiautomator.BasicSample"
to com.example.android.testing.uiautomator.BasicSample.test and perhaps make other changes

from testing-samples.

MohamedGaberM avatar MohamedGaberM commented on July 18, 2024

Espresso will wait for the app to be idle after the click is sent, so I strongly suspect this case cannot be handled in espresso. How does the code under test restart the app?

For UiAutomator, check out https://github.com/android/testing-samples/tree/main/ui/uiautomator/BasicSample. You'll likely need to adjust the targetProcess here

<instrumentation android:targetPackage="com.example.android.testing.uiautomator.BasicSample"

to com.example.android.testing.uiautomator.BasicSample.test and perhaps make other changes

The screen asks you to choose the required data then the app restarts with the data you choose before.

Intent i = activity.getBaseContext().getPackageManager().getLaunchIntentForPackage(activity.getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(i);
activity.finishAffinity();
System.exit(0);
```

> and i will check uiautomator, Thanks

from testing-samples.

brettchabot avatar brettchabot commented on July 18, 2024

Yeah there isn't a way to handle a System.exit(0) from an instrumentation test that runs in the same process

from testing-samples.

MohamedGaberM avatar MohamedGaberM commented on July 18, 2024

Yeah there isn't a way to handle a System.exit(0) from an instrumentation test that runs in the same process

yea I tried UI Automator and instrumentation crushed also, so is there any way to handle this case?

from testing-samples.

brettchabot avatar brettchabot commented on July 18, 2024

Did you configure the UI Automator instrumentation to run in a different process than the app under test? See the manifest link I gave above

from testing-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.