Re-opening the application through appium java script for the next test input

I ran appium java script successfully. But the problem is that My Application starts by entering the page. After logging in, I can automate some test cases. But I want to return from the login page again through a script in do the following test case. .How can I close the application as well as from the background and open the application again without restarting the application again? Because test files should not depend on each other

public class AppTest { private static RemoteWebDriver driver; @BeforeClass public static void initSimulator() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("platformVersion", "5.0.1"); capabilities.setCapability("deviceName", "emulator-5554"); capabilities.setCapability("app", "D:\\adt-bundle-windows-x86_64-20140702\\sdk\\platform-tools\\Yr.apk"); capabilities.setCapability("app-package", "com.you.android"); capabilities.setCapability("app-activity", "com.yr.sts.SplashActivity"); capabilities.setCapability("app_wait_activity",".MainActivity"); driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); System.out.println("App Launched"); } @AfterClass public static void quitDriver() { driver.quit(); System.out.println("Driver has been Quit"); } @Test public void sign_in_Click() throws InterruptedException { WebElement sign_button = driver.findElement(By.name("Sign-in")); sign_button.click(); WebElement usr = driver.findElement(By.id("com.you.android:id/et_login_email_or_mobile")); usr.sendKeys(" hello1@gmail.com "); Thread.sleep(2000); WebElement passwrd = driver.findElement(By.id("com.you.android:id/et_login_pwd")); passwrd.sendKeys("123456789"); Thread.sleep(2000); driver.findElementByName("Sign in").click(); Thread.sleep(5000); assertTrue( true ); } @Test public void second_sign_in_Click() throws InterruptedException { //HERE I WANT TO REOPEN THE APPLICATION WITH SIGN IN AFTER CLOSING APP.BECAUSE IN 1st TESTCASE , I HAVE SIGNED IN.this is a 2nd test case } } 
+5
source share
1 answer

change the tags @Beforeclass and @AfterClass to @Before and @After respectively.

Now your initSimulator () method will be called before every @Test, and after it the quitDriver () method will be called. Thus, you will have a new driver (with a transparent application), reloaded in each case.

So - as you can see - in JUnit, each test case is independent by default.

Why did your problem arise? From @ Docs BeforeClass :

Sometimes, several tests must share an expensive computing setup (such as entering a database). Although this can jeopardize the independence of the tests, sometimes it is a necessary optimization. Annotating the public static void no-arg method with @BeforeClass reasons it runs once before any of the testing methods in the class.

By the way, my initDriver () method looks like this, this is the best way to handle driver rejection:

  public void quitDriver() { driver.closeApp(); driver.quit(); driver = null; } 

(in your case it is static)

+1
source

All Articles