the end of the @test in class loginAppium , i want to call another class @test Class loginAppium
@Test
public void testLogin() {
driver.findElement(By.xpath("//*[@text='Login with your LabOra Id']")).click();
new WebDriverWait(driver, 100).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='Login' and @class='android.view.View']")));
driver.findElement(By.xpath("//*[@id='username']")).sendKeys("agrando.srilanka");
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='password']")));
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("embla");
driver.findElement(By.xpath("//*[@id='btnLogin']")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='Mönsterstad pastorat']")));
driver.findElement(By.xpath("//*[@text='Mönsterstad pastorat']")).click();
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
}
I want to call here
@Test
public void testaddAppointment() {
//Logout
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@class='android.widget.ImageView' and @width>0 and ./parent::*[@class='android.view.ViewGroup' and (./preceding-sibling::* | ./following-sibling::*)[./*[@text='Logout']]]]")));
driver.findElement(By.xpath("//*[@class='android.widget.ImageView' and @width>0 and ./parent::*[@class='android.view.ViewGroup' and (./preceding-sibling::* | ./following-sibling::*)[./*[@text='Logout']]]]")).click();
driver.findElement(By.xpath("//*[@text='Yes']")).click();
}
But it closes the app when at following stage
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
In Test script development, it is not a good practice to call a test method inside a test method.
Because every test method should be independent of other test methods.
Because of one test method, other test method should not get pass or fail. (This obviously differs from dependsOnMethods and dependsOnGroup) They have their own purposes.
A test method differs from a instance method or a static method.
A test method can have different-different test properties and test attribute with test data as well.
In your case :
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
Instead of this, try to make an instance method and call it inside a test methods.
Hope This will resolve your problem.
Let me know if you have any more concerns.
UPDATE :
I am wrapping this line of code. Please note that I have removed @Test annotation from this method
public void testaddAppointment() {
//Logout
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@class='android.widget.ImageView' and @width>0 and ./parent::*[@class='android.view.ViewGroup' and (./preceding-sibling::* | ./following-sibling::*)[./*[@text='Logout']]]]")));
driver.findElement(By.xpath("//*[@class='android.widget.ImageView' and @width>0 and ./parent::*[@class='android.view.ViewGroup' and (./preceding-sibling::* | ./following-sibling::*)[./*[@text='Logout']]]]")).click();
driver.findElement(By.xpath("//*[@text='Yes']")).click();
}
and you can call it like this :
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With