无法弄清楚我的第一个Appium ruby​​测试中的错误

时间:2018-06-08 16:10:04

标签: ios ruby appium appium-ios

require 'rubygems'
require 'appium_lib'

desired_caps = {
    caps: {
        platformName:  'iOS',
        platformVersion: '11.4',
        deviceName:    'iPhone 7',
        app:           Path,
        automationName: 'XCUITest',
    },
    appium_lib: {
        sauce_username:   nil,
        sauce_access_key: nil,
        wait: 60
    }
}

driver = Appium::Driver.new(desired_caps)
Appium.promote_appium_methods AppiumWorld
driver.start_driver

#login test class

    #find the email textfield
    def email(driver)
        return driver.find_element(:name, "Email")
    end

    #find the password textfield
    def password(driver)
        return driver.find_element(:name, "Password")
    end

    #find the login button
    def loginButton(driver)
        return driver.find_element(:name, "Login")
    end

    #find Forgot Password button
    def forgotPasswordButton(driver)
        return driver.find_element(:name, "Forgot Password?")
    end

    #find Don't have an account button
    def forgotAccountButton(driver)
        return driver.find_element(:name, "Don't have an account?")
    end

$driver.driver_quit

我还没有包含这条路,但这是正确的。我已经安装了所有需要的宝石,ruby运行appium ruby​​测试的唯一依赖是我安装的appium_lib。我想确保我有2个必需的电子邮件和密码的文本字段和3个按钮,其中包括登录,忘记密码,以及没有帐户按钮。这是我得到的错误,我似乎无法找到解决此错误的方法:

Traceback (most recent call last):
    2: from loginScreenTest.rb:2:in `<main>'
    1: from /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- appium_lib (LoadError

1 个答案:

答案 0 :(得分:0)

此测试的目的是检查视图控制器上是否存在所有UI元素。为了找到那些“元素”,需要使用name,id甚至xpath引用这些元素(不建议这样做,因为它根据Appium模拟器所说的而不是我的文字创建了不稳定的测试)。特别是我的代码问题首先是我需要安装gem,所以我运行了该代码,但最终工作的代码如下。

require 'rubygems'
require 'appium_lib'

desired_caps = {
    caps: {
        platformName:  'iOS',
        platformVersion: '11.4',
        deviceName:    'iPhone 7',
        app:           PATH,
        automationName: 'XCUITest',
    },
    appium_lib: {
        sauce_username:   nil,
        sauce_access_key: nil,
        wait: 60
    }
}

@driver = Appium::Driver.new(desired_caps,)

@driver.start_driver

#login test class

    #find the email textfield
    def email(driver)
        if driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField')
            return driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField')
        end
    end

    #find the password textfield
    def password(driver)
        if driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField')
            return driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField')
        end
    end

    #find the login button
    def loginButton(driver)
       if driver.find_element(:name, "Login")
           return driver.find_element(:name, "Login")
        end
    end

    #find Forgot Password button
    def forgotPasswordButton(driver)
        if driver.find_element(:name, "Forgot your password?")
            return driver.find_element(:name, "Forgot your password?")
        end
    end

    #find Don't have an account button
    def forgotAccountButton(driver)
        if driver.find_element(:name, "Don't have an account?")
            return driver.find_element(:name, "Don't have an account?")
        end
    end

    #remember me button
    def rememberMeButton(driver)
        if driver.find_element(:name, "Remember me")
            return driver.find_element(:name, "Remember me")
        end
    end

    #toggle
    def toggle(driver)
        if driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeSwitch')
            return driver.find_element(:xpath, '//XCUIElementTypeApplication[@name="DataSiteOne"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeSwitch')
        end
    end


    email(@driver)
    password(@driver)
    loginButton(@driver)
    forgotPasswordButton(@driver)
    forgotAccountButton(@driver)
    rememberMeButton(@driver)
    toggle(@driver)

@driver.driver_quit