2

「title_I_need」というタイトルのボタンが存在するかどうかを確認する必要があります。存在する場合はそれを押して、そうでない場合は別のものを押します。これらはすべて JavaScript で書かれています。

Appium.App テストに記録し、ボタンが存在する場合は検証を追加しました。私は JavaScript にあまり詳しくないので、Objective-C から始めました。しかし、結果として、常に title_I_need ボタンをクリックしますが、私の期待は、other_title ボタンによる else ブランチです。

Appiumでそのようなチェックを行うことはできますか? はいの場合、JavaScript (node.js) でこれを行うにはどうすればよいですか?

#import <Selenium/SERemoteWebDriver.h>

@implementation SeleniumTest

-(void) run
{
    SECapabilities *caps = [SECapabilities new];
    [caps addCapabilityForKey:@"appium-version" andValue:@"1.0"];
    [caps setPlatformName:@"iOS"];
    [caps setPlatformVersion:@"8.4"];
    [caps setDeviceName:@"device_name"];
    [caps setApp:@"/path/AppName.app"];
    NSError *error;
    SERemoteWebDriver *wd = [[SERemoteWebDriver alloc] initWithServerAddress:@"0.0.0.0" port:4723 desiredCapabilities:caps requiredCapabilities:nil error:&error];
    //check for element with wrong not existed title to go to else branch
    if ([wd findElementBy:[SEBy name:@"wrong_title"]]){
    [[wd findElementBy:[SEBy name:@"title_I_need"]] click];
  } else {
    [[wd findElementBy:[SEBy name:@"other_title"]] click];
  }
}

@end
4

1 に答える 1

2

これを行う最も簡単な方法は、配列を返す( sfindElementsByに注意してください) を使用することです。次に、配列が空かどうかを確認します。これを関数に入れて、 のように呼び出します。これに対応する Java メソッドは次のようになります。doesElementExists

public boolean doesElementExists(By by) {
    try {
        List allElements = driver.findElements(by);
        if ((allElements == null) || (allElements.size() == 0))
            return false;
        else
            return true;
    } catch (java.util.NoSuchElementException e) {
        return false;
    }
}
于 2016-03-15T16:09:47.520 に答える