TestNG 从另一个测试方法调用一个测试方法
TestNG Calling to a test method from another test method
class loginAppium 中的@test 结束,我想调用另一个class @test
Class 登录Appium
@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();
}
我要打电话给这里
@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();
}
但是在接下来的阶段它会关闭应用程序
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
在测试脚本开发中,在测试方法内部调用测试方法不是一个好习惯。
因为每个测试方法都应该独立于其他测试方法。
因为一种测试方法,其他测试方法不应该通过或失败。 (这明显不同于 dependsOnMethods 和 dependsOnGroup)
他们有自己的目的。
测试方法不同于实例方法或静态方法。
测试方法可以具有 different-different 测试属性和带有测试数据的测试属性。
你的情况:
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
取而代之的是,尝试创建一个实例方法并在测试方法中调用它。
希望这能解决您的问题。
如果您还有任何疑虑,请告诉我。
更新:
我正在包装这行代码。请注意,我已从此方法中删除了@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();
}
你可以这样称呼它:
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
我建议从另一个 class 中删除 @Test annotation
,并将其命名为
你有定义。
另一种方法是,您可以在基 class 中扩展目标 class 并在没有任何 annotation dependency
的情况下调用该方法。
class loginAppium 中的@test 结束,我想调用另一个class @test Class 登录Appium
@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();
}
我要打电话给这里
@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();
}
但是在接下来的阶段它会关闭应用程序
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
在测试脚本开发中,在测试方法内部调用测试方法不是一个好习惯。
因为每个测试方法都应该独立于其他测试方法。
因为一种测试方法,其他测试方法不应该通过或失败。 (这明显不同于 dependsOnMethods 和 dependsOnGroup) 他们有自己的目的。
测试方法不同于实例方法或静态方法。
测试方法可以具有 different-different 测试属性和带有测试数据的测试属性。
你的情况:
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
取而代之的是,尝试创建一个实例方法并在测试方法中调用它。
希望这能解决您的问题。
如果您还有任何疑虑,请告诉我。
更新:
我正在包装这行代码。请注意,我已从此方法中删除了@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();
}
你可以这样称呼它:
addAppointment addApp = new addAppointment();
addApp.testaddAppointment();
我建议从另一个 class 中删除 @Test annotation
,并将其命名为
你有定义。
另一种方法是,您可以在基 class 中扩展目标 class 并在没有任何 annotation dependency
的情况下调用该方法。