Last active
May 10, 2019 05:21
-
-
Save ZhouMeichen/979b2fe326cb3d781fcc to your computer and use it in GitHub Desktop.
UI layer smoke test with Selenium+Cucumber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #encoding: utf-8 | |
| class Browser | |
| def self.init | |
| if ARGV[0].to_s.downcase == "firefox" | |
| @driver = Selenium::WebDriver.for :firefox | |
| elsif ARGV[0].to_s.downcase == "chrome" | |
| @driver = Selenium::WebDriver.for :chrome | |
| elsif ARGV[0].to_s.downcase == "ie" | |
| @driver = Selenium::WebDriver.for :ie | |
| else | |
| @driver = Selenium::WebDriver.for :firefox | |
| end | |
| end | |
| def self.close | |
| @driver.quit | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #encoding: utf-8 | |
| require 'selenium-webdriver' | |
| require 'minitest/autorun' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #encoding: utf-8 | |
| driver = Browser.init | |
| #login | |
| Given /^I visit spi webpage "(.*?)", and I input username "(.*)" and password "(.*)", and I click login button$/ do |site, usr, pwd| | |
| driver.navigate.to site | |
| element = driver.find_element(:id, "txtAccount") | |
| element.send_keys usr | |
| element = driver.find_element(:id, "txtPassword") | |
| element.send_keys pwd | |
| element = driver.find_element(:id, "btnLogin") | |
| element.click | |
| end | |
| #Scenario: Sys_RoleManagement_DIY_Add | |
| When /^I visit Role Management DIY page, and I input role name as "(.*)", then I click save button$/ do |role| | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[1]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btnAdd']").click | |
| sleep 2 | |
| driver.switch_to.default_content #先切换到默认 | |
| driver.switch_to.frame("dialogFrame") | |
| driver.find_element(:id, "txtRole").send_keys role #随机数 | |
| driver.find_element(:id, "btnSave").click | |
| sleep 2 | |
| #driver.find_element(:class, "ui-dialog-titlebar-close ui-corner-all").click | |
| #driver.find_element(:xpath, "/html/body/div[2]/div[1]/a").click | |
| driver.navigate.to "http://172.29.140.157/SPI/SystemManagement/Role/RoleList.aspx" | |
| end | |
| #Scenario: Sys_RoleManagement_DIY_Delete | |
| When /^I visit Role Management DIY page, and I click delete button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[1]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| sleep 2 | |
| driver.find_element(:id, "cbx_1").click | |
| driver.find_element(:xpath, "//*[@id='btnDeleteBatch']").click | |
| sleep 2 | |
| driver.navigate.to "http://172.29.140.157/SPI/SystemManagement/Role/RoleList.aspx" | |
| end | |
| #Scenario: Sys_RoleManagement_Default_Show | |
| When /^I visit Role Management default page$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[1]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:id,"lbtnSystem").click | |
| end | |
| #Scenario: Sys_UserManagement_Search | |
| When /^I visit User Management page, and I click search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[2]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btnSearch']").click | |
| end | |
| #Scenario: Sys_UserManagement_Add | |
| When /^I visit User Management page, and I click add button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[2]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btnAdd']").click | |
| sleep 2 | |
| driver.switch_to.default_content #先切换到默认 | |
| driver.switch_to.frame("dialogFrame") | |
| driver.find_element(:id, "txtAccount").send_keys 'tester' | |
| driver.find_element(:id, "txtName").send_keys 'tester' | |
| dropdown = driver.find_element(:id, "ddlStatus") | |
| select_list = Selenium::WebDriver::Support::Select.new(dropdown) | |
| select_list.select_by(:text, '激活') | |
| driver.find_element(:id, "txtEmail").send_keys '[email protected]' | |
| driver.find_element(:id, "cblRoles_8").click | |
| driver.find_element(:id, "btnSave").click | |
| sleep 5 | |
| #driver.find_element(:class, "ui-dialog-titlebar-close ui-corner-all").click | |
| #driver.find_element(:xpath, "/html/body/div[2]/div[1]/a").click | |
| driver.navigate.to "http://172.29.140.157/SPI/SystemManagement/User/UserList.aspx" | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='btnSearch']").click | |
| end | |
| #Scenario: Sys_UserManagement_Delete | |
| When /^I visit User Management page, and I click delete button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[2]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btnSearch']").click | |
| sleep 2 | |
| driver.find_element(:id, "cbx_1").click | |
| driver.find_element(:xpath, "//*[@id='btnDeleteBatch']").click | |
| sleep 2 | |
| driver.navigate.to "http://172.29.140.157/SPI/SystemManagement/User/UserList.aspx" | |
| sleep 5 | |
| driver.find_element(:xpath, "//*[@id='btnSearch']").click | |
| end | |
| #Scenario: Sys_BusinessException_Search | |
| When /^I click business exception link, and input fromdate "(.*)" and todate "(.*)", and I click search button$/ do |from,to| | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[1]/p[3]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| # page.within_frame("mainFrame") do | |
| driver.find_element(:xpath, "//*[@id='dp_BeginSystemReciveTime']").send_keys from | |
| driver.find_element(:xpath, "//*[@id='dp_EndSystemReciveTime']").send_keys to | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| # end | |
| end | |
| #Scenario: Sys_BankException_Search | |
| When /^I click bank exception link, and input fromdate "(.*)" and todate "(.*)", and I click search button$/ do |from,to| | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[4]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[1]/p[4]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| #page.within_frame("mainFrame") do | |
| driver.find_element(:xpath, "//*[@id='dp_BeginSystemReciveTime']").send_keys from | |
| driver.find_element(:xpath, "//*[@id='dp_EndSystemReciveTime']").send_keys to | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| #end | |
| end | |
| #Scenario: Sys_HSBCFailure_Show | |
| When /^I visit HSBC Failure page$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[1]/p[5]/a").click | |
| sleep 2 | |
| #driver.switch_to.frame("mainFrame") | |
| #driver.find_element(:id,"lbtnSystem").click | |
| end | |
| #Scenario: Salary_Pay_Confirm | |
| When /^I click salary pay link$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[2]/p[1]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[2]/p[1]/a").click | |
| sleep 5 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:id,"cbx_1").click | |
| driver.find_element(:id,"btn_Confirm").click | |
| sleep 5 | |
| driver.switch_to.default_content | |
| #driver.find_elements(:tag_name, "a").click | |
| driver.find_element(:id,"dp_PaymentDate").clear | |
| driver.find_element(:id,"dp_PaymentDate").send_keys "2015-02-07" | |
| driver.find_element(:xpath,"//*[@class='ui-dialog-buttonset']/button[1]").click | |
| sleep 2 | |
| driver.navigate.to "http://172.29.140.157/SPI/SalaryPaymentConfirm" | |
| #page.within_frame("mainFrame") do | |
| #driver.find_element(:xpath, "//*[@id='btn_DetailsSearch']").click | |
| #end | |
| end | |
| #Scenario: Salary_Status_Search | |
| When /^I click salary status search link, and click search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[2]/p[2]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[2]/p[2]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| #page.within_frame("mainFrame") do | |
| #find(:xpath, "//*[@id='btn_Search']").click | |
| #end | |
| end | |
| #Scenario: Salary_Detail_Status_Search | |
| When /^I click salary detail status search link, and click search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[2]/p[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[2]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[2]/p[3]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| #page.within_frame("mainFrame") do | |
| #find(:xpath, "//*[@id='btn_Search']").click | |
| #end | |
| end | |
| #Scenario: Nonsalary_Pay_Confirm | |
| When /^I click nonsalary pay link$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[3]/p[1]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[3]/p[1]/a").click | |
| # sleep 5 | |
| # page.within_frame("mainFrame") do | |
| # find(:xpath, "//*[@id='btn_Search']").click | |
| # end | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:id,"cbx_1").click | |
| driver.find_element(:id,"btn_Confirm").click | |
| sleep 5 | |
| driver.switch_to.default_content | |
| #driver.find_elements(:tag_name, "a").click | |
| driver.find_element(:id,"dp_PaymentDate").clear | |
| driver.find_element(:id,"dp_PaymentDate").send_keys "2015-02-09" | |
| driver.find_element(:xpath,"//*[@class='ui-dialog-buttonset']/button[1]").click | |
| sleep 2 | |
| driver.navigate.to "http://172.29.140.157/SPI/NonSalaryLE" | |
| end | |
| #Scenario: Nonsalary_Status_Search | |
| When /^I click nonsalary status search link, and click detail search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[3]/p[2]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[3]/p[2]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btn_DetailsSearch']").click | |
| #page.within_frame("mainFrame") do | |
| #find(:xpath, "//*[@id='btn_DetailsSearch']").click | |
| #end | |
| end | |
| #Scenario: Nonsalary_Exception_Detail_Search | |
| When /^I click nonsalary exception detail search link, and click search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[3]/p[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[3]/p[3]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| #page.within_frame("mainFrame") do | |
| #find(:xpath, "//*[@id='btn_Search']").click | |
| # end | |
| end | |
| #Scenario: Nonsalary_Salary_Pay_Result | |
| When /^I click nonsalary salary pay result link, and click search button$/ do | |
| driver.find_element(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| sleep 2 | |
| driver.find_element(:xpath, "//*[@id='accordion']/div[3]/p[4]/a").click | |
| #find(:xpath, "//*[@id='accordion']/h3[3]/a").click | |
| #find(:xpath, "//*[@id='accordion']/div[3]/p[4]/a").click | |
| sleep 2 | |
| driver.switch_to.frame("mainFrame") | |
| driver.find_element(:xpath, "//*[@id='btn_Search']").click | |
| #page.within_frame("mainFrame") do | |
| #find(:xpath, "//*[@id='btn_Search']").click | |
| #end | |
| end | |
| #frame content then | |
| Then /^I will see the text "(.*)" in frame "(.*)", and I will see screenshot in path "(.*)"$/ do |e,f,p| | |
| sleep 2 | |
| unless f.empty? | |
| driver.switch_to.default_content | |
| driver.switch_to.frame(f) | |
| end | |
| sleep 2 | |
| element = driver.find_element(:tag_name, "body") | |
| assert_includes(element.text.to_s,e,"failed message") | |
| driver.save_screenshot(p) | |
| Browser.close | |
| end | |
| #frame content then | |
| Then /^I will not see the text "(.*)" in frame "(.*)", and I will see screenshot in path "(.*)"$/ do |e,f,p| | |
| sleep 2 | |
| unless f.empty? | |
| driver.switch_to.default_content | |
| driver.switch_to.frame(f) | |
| end | |
| sleep 2 | |
| element = driver.find_element(:tag_name, "body") | |
| boo = !(element.text.include? e) | |
| assert(boo,"failed message") | |
| driver.save_screenshot(p) | |
| Browser.close | |
| end | |
| #frame content then | |
| Then /^I will get the element by id "(.*)" in frame "(.*)", and I will see screenshot in path "(.*)"$/ do |e,f,p| | |
| sleep 2 | |
| unless f.empty? | |
| driver.switch_to.default_content | |
| driver.switch_to.frame(f) | |
| end | |
| element = driver.find_element(:id, e) | |
| boo = element.displayed? | |
| assert(boo,"failed message") | |
| driver.save_screenshot(p) | |
| Browser.close | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment