无法在第二个测试类中使用超类对象,但可以在第一个测试类中使用它

时间:2017-06-12 06:46:19

标签: selenium-webdriver automated-tests testng testng-eclipse

我有一个名为BaseTest的超类,代码为

public class BaseTest {
    public AndroidDriver<AndroidElement> driver;
    DesiredCapabilities cap;
    @BeforeTest
    @Parameters("device")
    public void SetUpForDriver(String device) throws MalformedURLException{
        if(device.equalsIgnoreCase("emulator")){
            cap = new DesiredCapabilities();
            cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
            cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");
            cap.setCapability(MobileCapabilityType.DEVICE_NAME, "SlingEmulator");
            //cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
            cap.setCapability("appPackage", "com.edmobilelabs.sling.dev");
            //cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.edmobilelabs.sling.ui.ScrSplash");
            cap.setCapability("appActivity", "com.edmobilelabs.sling.ui.ScrSplash");
            driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);

    }
        else{
            cap = new DesiredCapabilities();
            cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
            cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
            cap.setCapability(MobileCapabilityType.DEVICE_NAME, "28A4AA040IG4012");
            cap.setCapability("appPackage", "com.edmobilelabs.sling.dev");
            cap.setCapability("appActivity", "com.edmobilelabs.sling.ui.ScrSplash");
            driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        }
    }
}

我能成功执行的Ist Test课程

public class LogInPageTest extends BaseTest {
    LogInPage log;

    @Test(priority=1)
    public void navigateToLoginPageTest() throws MalformedURLException{
        log = new LogInPage(driver);
        boolean isTestCaseVerified = log.navigateToLoginPage();
        Assert.assertTrue(isTestCaseVerified,"Test Case is Passed");
    }
}

我的第二个测试类我想在其中使用驱动程序对象

public class HomePageTest extends BaseTest{

    @Test(priority=2)
    public void firstChatWithBots(){
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//android.widget.Button[@text='How Sling Works']")).click();
    }
}

我有两个测试类 我执行登录操作的测试类成功传递但在我的第二个测试类中无法使用我的驱动程序对象

有人可以使用我的代码

0 个答案:

没有答案