Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Service Automation Framework

Avatar for Chaoyi Chaoyi
July 26, 2013
38

Service Automation Framework

Avatar for Chaoyi

Chaoyi

July 26, 2013
Tweet

Transcript

  1. Goals • Easy to add new service • Very readable

    test cases • Fully control of method/url query/body/header • Flexible results checking (JSON path handling) • Easy environment switch
  2. Overview • Entire framework written in Ruby 2.0 • Test

    cases use RSpec or Cucumber • Switching between different servers is controlled by environment variable (SERVER)
  3. Usage - make service HTTP(S) request • Service -> Class

    ◦ Each service is wrapped into a class with the same name as the service name. • Methods -> Instance methods ◦ Each method defined by the service also has the same name as an instance method. • Fully control of :method, :url_query, : header, :body • e.g.: t = Taxonomy.new("http://mobile.walmart.com/m/j") t.searchByDepartment
  4. Usage - add new service • Don't need to define

    new class/methods • The framework uses the names to automatically generate everything • Just put the service name, method name and default params in walmart_services.yml file.
  5. Example After you add the following: You'll have: t =

    Foo.new("http://your_service_host") t.bar
  6. Usage - verify response • The framework uses two specific

    Ruby gems to help for the JSON validation ◦ JsonPath: XPath for JSON ◦ json_spec: new Rspec matchers to handle JSON • Customized matcher
  7. Usage - write test require_relative '../spec_helper' describe "Service::Taxonomy", :qa =>

    true do before(:all) do @taxonomy = Taxonomy.new(RSpec.configuration.global_test_env["server_address"]) end describe "Method::getAllDepartments", :production => true do it "get all departments with GET" do url_query_param = { :e => "1", } @taxonomy.getAllDepartments({:url_query => url_query_param}) @taxonomy.response.code.should eql(200) @taxonomy.response.body.should be_taxonomy_get_all_departments_response end end end
  8. Usage - run test suites • Server configurations are predefined

    in config/config.yml • $ rake • $ SERVER=production|qa1|qa2|qa3 PROXY=true|false rake • $ rspec -fd -c <test_suite_path> • $ rspec -fd -c <test_suite_path> -l <test_case_line_number>