2015-10-19 61 views
0

這可能是專家的簡單問題。我是一名初學者,現在我一直在試圖製作測試腳本來在腳本中打印頁面標題。以下是我的代碼的一部分:我無法打印頁面標題,然後進行驗證。有人可以幫忙嗎?Appium Android自動化

driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
     System.out.println(driver.getRemoteAddress()); 
} 

public void ApkPushValidation() throws Exception { 

Assert.assertEquals("Verify your phone number", driver.findElementByName("Verify your phone number").getText()); 

    driver.wait(5000); 
    String i = driver.getTitle(); 
    System.out.println(i); 


if (driver.getTitle().equals("Verify your phone number")) { 

    System.out.println("app installation is passed"); 

} else { 

System.out.println("App installation is failed"); 

} 

//System.out.println(i);---> my expectation is that this will print out Verify your Phone number. However this is not printing the page title. 

回答

0

我認爲driver.getTitle()是Web頁面的交互,並不意味着本地應用程序的方法。我會建議使用XPath或其他元素定位器來查找標題。

+0

你是說在按名稱查找元素之前添加一個driver.wait ?.如果是,那麼它也沒有工作。運行後,我的控制檯出錯: –

+1

失敗:ApkPushTest org.openqa.selenium.WebDriverException:尚未實施。請幫助我們:http://appium.io/get-involved.html(警告:服務器未提供任何堆棧跟蹤信息) 命令持續時間或超時:16毫秒 –

+0

您提供的日誌正在證實我的懷疑。此方法不適用於使用。 –

0

取而代之的是,如果getTitle();嘗試使用xPath,名稱或Id可用於標題。使用Appium檢查器或UI自動工具來定位該元素並像這樣更改它:

String i = driver.findElementById("Your ID").getText(); 
if (i.equals("Verify your phone number")) { 
    System.out.println("app installation is passed"); 

} else { 

System.out.println("App installation is failed"); 

} 
+0

謝謝Gaurav。那麼我用AssertEquals方法來驗證預期的字符串,它的工作。 –

0

你大概是什麼執行應該使用下面的一段代碼來完成什麼:

WebElement title = driver.findElementByName("Verify your phone number"); // defining the element only once for multiple use 
// different locator strategies could be used for locating the element above 

Assert.assertEquals("Verify your phone number", title.getText()); 
driver.wait(5000); 
String i = title.getText(); 
System.out.println(i);  
if (i.equals("Verify your phone number")) { 
    System.out.println("app installation is passed"); 
} else { 
    System.out.println("App installation is failed"); 
} 

更多driver.getTitle():它已經從RemoteWebDriver繼承和可能應該返回一個網頁的標題/ webview而不是本地應用程序視圖,這似乎是你的情況。

:將增加更多的這個約的getTitle(),因爲我瞭解。

相關問題