11

と一緒にnew Xcode UI Testingfromを使っています。シンプルな UIWebView を備えたアプリ (ナビゲーション コントローラー + Web ビューとボタンを備えたビュー コントローラー) があり、次のシナリオを確認したいと考えています。XCTest FrameworkXcode 7 GM

  1. Web ビューの読み込みページwww.example.com
  2. ユーザーがボタンをタップ
  3. Web ビューは URL を含むページを読み込みます:www.example2.com

ボタンを押した後、UIWebViewにどのページが読み込まれているかを確認したい。これは現在 UI テストで可能ですか?

実際、私は次のようなWebビューを取得しています:

let app:XCUIApplication = XCUIApplication()
let webViewQury:XCUIElementQuery = app.descendantsMatchingType(.WebView)
let webView = webViewQury.elementAtIndex(0)
4

2 に答える 2

13

表示されている実際の URL のように、どのページが読み込まれているかを知ることはできません。ただし、アサート コンテンツが画面上にあることを確認することはできます。UI Testing は、 と の両方でうまく機能するforXCUIElementQueryリンクUIWebViewWKWebView提供します。

ページは同期的に読み込まれないため、実際の要素が表示されるまで待つ必要があることに注意してください。

let app = XCUIApplication()
app.launch()

app.buttons["Go to Google.com"].tap()

let about = self.app.staticTexts["About"]
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: about, handler: nil)

waitForExpectationsWithTimeout(5, handler: nil)
XCTAssert(about.exists)

XCTAssert(app.staticTexts["Google Search"].exists)
app.links["I'm Feeling Lukcy"].tap()

コードを掘り下げたい場合は、2 つのリンクに沿って動作するテスト ホストもあります。

于 2015-09-17T10:15:27.947 に答える
3

ページのタイトルが異なる場合は、Web ページのタイトルを確認できます。

let app = XCUIApplication()
app.launch()
//Load www.example.com

//Tap on some button    
app.links["Your button"].tap()

//Wait for www.example2.com to load
let webPageTitle = app.otherElements["Example2"]
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: webPageTitle, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
于 2015-09-25T00:46:06.377 に答える