zoukankan      html  css  js  c++  java
  • ruby+seleniumwebdriver一步一步完成自动化测试(5)—–多个测试用例

    在上一篇“逻辑与数据分离”中只有一个测试用例,在这篇中主要是针对多个用例。验证用户名、密码全部错误;用户名、密码全部为空;用户名为空;密码为空,几种情况登录。

    1.D盘新建文件夹test005,文件结构与“逻辑与数据分离中一致”

    2.login_dialog.rb文件内容与上一篇“面向对象编程”中login_dialog.rb内容一致

    3.login_main_page.rb文件内容与上一篇“面向对象编程”中login_main_page.rb内容一致

    4.login_data.yml文件中编写如下内容:

    data:
      mainPage:
        url: http://www.soso.com
        title: 搜搜更懂你  
    
      login:
        wrong:
          username: test
          password: test
          message: 您输入的帐号或密码不正确,请重新输入。意见反馈  
    
        allNotExist:
          username:
          password:
          message: 您还没有输入帐号!意见反馈  
    
        usernameNotExist:
          username:
          password: test
          message: 您还没有输入帐号!意见反馈  
    
        passwordNotExist:
          username: test
          password:
          message: 您还没有输入密码!意见反馈  
    

      5.login_spec.rb文件中编写如下内容:

    #encoding: utf-8
    require "rspec"
    require 'yaml'
    require 'selenium-webdriver'  
    
    require File.dirname(__FILE__)+'/../tool/login_dialog'
    require File.dirname(__FILE__)+'/../action/login_main_page'  
    
    describe "soso login" do
      include LoginDialog
      #before(:all) do
      #  @problem=YAML.load(File.open(File.dirname(__FILE__)+'/http://www.cnblogs.com/sosoLogin/config/login_data.yml'))
      #  @dr=Selenium::WebDriver.for :firefox
      #  @url=@problem["data"]["mainPage"]["url"]
      #  @dr.get @url
      #end
      before(:each) do
        @problem=YAML.load(File.open(File.dirname(__FILE__)+'/../config/login_data.yml'))
        @dr=Selenium::WebDriver.for :firefox
        @url=@problem["data"]["mainPage"]["url"]
        @dr.get @url
        @login_element=LoginMainPage.new(@dr)
      end
      after(:each) do
         close_browser
      end
      it "should should open soso url" do
        @dr.title.should eql (@problem["data"]["mainPage"]["title"])
      end  
    
      it "should return username and password is wrong" do
        @login_element.login(@problem["data"]["login"]["wrong"]["username"],@problem["data"]["login"]["wrong"]["password"])
        err_message.should eql (@problem["data"]["login"]["wrong"]["message"])
      end  
    
      it "should return username and password are not exist" do
        @login_element.login(@problem["data"]["login"]["allNotExist"]["username"],@problem["data"]["login"]["allNotExist"]["password"])
        err_message.should eql (@problem["data"]["login"]["allNotExist"]["message"])
      end  
    
      it "should return username is not exist" do
        @login_element.login(@problem["data"]["login"]["usernameNotExist"]["username"],@problem["data"]["login"]["usernameNotExist"]["password"])
        err_message.should eql (@problem["data"]["login"]["usernameNotExist"]["message"])
      end  
    
      it "should return password is not exist" do
        @login_element.login(@problem["data"]["login"]["passwordNotExist"]["username"],@problem["data"]["login"]["passwordNotExist"]["password"])
        err_message.should eql (@problem["data"]["login"]["passwordNotExist"]["message"])
      end
    end
    

      

    6.命令行运行命令:

    cd d:\test005

    rspec -f doc

    得到如下结果:

    soso login
      should should open soso url
      should return username and password is wrong
      should return username and password are not exist
      should return username is not exist
      should return password is not exist  
    
    Finished in 49.11 seconds
    5 examples, 0 failures
    

      运行通过

  • 相关阅读:
    组件传值---组件与弹窗组件传值
    elementUI拿到当前表格行的数据的另一种写法
    elementUi-复选框,使用v-for循环出来的复选框,默认多个值为勾选状态
    点击事件,根据不同的下标实现切换不同的内容
    elementUI表格行的点击事件,点击表格,拿到当前行的数据
    在使用element-ui搭建的表格中,实现点击"定位"按钮后,屏幕滚动到对应行的位置
    renren-fast-vue-动态路由-添加路由-方式一(直接在原有结构上添加)
    renren-fast-vue-动态路由
    vue-element-admin打包后白屏的问题
    2月20日-寒假学习进度20
  • 原文地址:https://www.cnblogs.com/timsheng/p/2682652.html
Copyright © 2011-2022 走看看