zoukankan      html  css  js  c++  java
  • AutoIT: 开发界面结合GUI automation和Watir Automation

    可以应用AutoIT开发出界面,从而把AutoIT对GUI的自动化测试与Watir对web的自动化测结合在一起。
    以下代码是我学习GUI界面开发的实例代码。
    1. 当点击Watir_Test_Button,就会打开IE 浏览器,到达百度页面;
    2. 当点击GUI_Automation_Test,就会打开notepad,并在其中输入一些文字。

    #include <GuiConstantsEx.au3>
    #include <AVIConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <WindowsConstants.au3>
    #include <StaticConstants.au3>
    #include <TreeViewConstants.au3>
    
    ; Window, Pic, Label, Lable background color
    GUICreate("Sample GUI", 800, 500)
    ;GUICtrlCreatePic("C:UserschenpassionDesktopBeautywesley1.png", 0, 0, 800, 500)
    ;GuiCtrlSetState(-1,$GUI_DISABLE)
    GUICtrlCreateLabel("Beauty Pic", 75, 1, 80, 50)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0xFFFFFF)
    
    ; Set Title Icon
    GUISetIcon("D:Thunder NetworkThunderProgramXmpIconmov.ico")
    $filemenu = GUICtrlCreateMenu("&File")
    $openitem = GUICtrlCreateMenuItem("Open", $filemenu)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    $helpmenu = GUICtrlCreateMenu("?")
    GUISetHelp("NOTEPAD.EXE")
    
    ;Set Menu, MenuItem
    $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1)
    $recentfilesmenuchild = GUICtrlCreateMenuItem("C:\Program", $recentfilesmenu)
    $recentfilesmenuchild = GUICtrlCreateMenuItem("D:\Program", $recentfilesmenu)
    $separator1 = GUICtrlCreateMenuItem("", $filemenu, 2)
    $viewmenu = GUICtrlCreateMenu("View", -1, 3)
    $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    
    ;Create button
    $okbutton = GUICtrlCreateButton("OK", 20, 20, 70, 20)
    GUICtrlSetState(-1, $GUI_FOCUS)
    $cancelbutton = GUICtrlCreateButton("Cancel", 100, 20, 70, 20)
    ;GUICtrlSetState(-1, $GUI_FOCUS)
    
    $cancelbutton2 = GUICtrlCreateButton("Cancel2", 100, 40, 70, 20)
    
    ;Create Context Menu
    $buttoncontext = GUICtrlCreateContextMenu($okbutton)
    $buttonitem1 = GUICtrlCreateMenuItem("About button 1", $buttoncontext)
    $buttonitem2 = GUICtrlCreateMenuItem("About button 2", $buttoncontext)
    $Cancelcontext = GUICtrlCreateContextMenu($cancelbutton)
    $buttonitem3 = GUICtrlCreateMenuItem("About Cancel Button", $Cancelcontext)
    
    ;Create AVI
    $ani1 = GUICtrlCreateAvi(@SystemDir & "shell32.dll", 165, 20, 70)
    GUICtrlSetBkColor(-1, 0x00ff00)
    $buttonstart = GUICtrlCreateButton("start", 50, 140, 70, 22)
    $buttonstop = GUICtrlCreateButton("stop", 150, 140, 70, 22)
    
    ;Tab test
    $child1_tab = GUICtrlCreateTab(20, 230, 370, 215)
    $child1_tabitem1 = GUICtrlCreateTabItem("Child1Tab1")
    $child1_tabitem2 = GUICtrlCreateTabItem("Child1Tab2")
    $buttonTab = GUICtrlCreateButton("OK2", 20, 250, 50, 30)
    ;GUICtrlSetState(-1, $GUI_SHOW)
    ;GUISetState(@SW_SHOW)
    $child1_tabitem3 = GUICtrlCreateTabItem("")
    GUICtrlSetState(-1, $GUI_SHOW)
    
    ;Combo, setfont, GUICtrlSetFont
    $font = "Comic Sans MS"
    $fontlabel = GUICtrlCreateLabel("Combo Test: ", 160, 280, 120, 20)
    GUICtrlSetFont($fontlabel,10, 20, 2, $FONT)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $comboFont = GUICtrlCreateCombo("", 250, 277, 120, 100, $CBS_DROPDOWNLIST)
    GUICtrlSetFont($comboFont,10, 20, 2+4, $font)
    GUICtrlSetData($comboFont, "Sample Combo|Item2|Item3", "Item3")
    
    ; PROGRESS
    $progress_bar = GUICtrlCreateProgress(160, 320, 150, 20)
    GUICtrlCreateLabel("Progress:", 100, 322)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    ; EDIT
    GUICtrlCreateEdit("Type your Name here: ", 300, 20, 200, 120,  BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
    
    ; LIST
    GUICtrlCreateList("", 520, 20, 100, 90)
    GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "D.Here")
    
    ;Create Icon
    GUICtrlCreateIcon("explorer.exe", 550, 175, 20)
    GUICtrlCreateLabel("Icon", 510, 175, 50, 20)
    
    ;Listview
    $listview = GUICtrlCreateListView("col1  |col2|col3  ", 520, 180, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
    $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
    $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
    
    $Watir_Test_button = GUICtrlCreateButton("Watir_Test_Button", 150, 180, 120, 20)
    $GUI_Automation_Test = GUICtrlCreateButton("GUI_Automation_Test", 280, 180, 120, 20)
    
    
    GUICtrlCreateInput("Hello", 320, 400, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
    GUICtrlSetData($item2, "ITEM1")
    GUICtrlSetData($item3, "||COL33")
    
    ; TREEVIEW TWO
    Local $iTreeView_2 = GUICtrlCreateTreeView(520, 350, 130, 120, $TVS_DISABLEDRAGDROP)
    GUICtrlCreateTreeViewItem("TreeView", $iTreeView_2)
    GUICtrlCreateTreeViewItem("With", $iTreeView_2)
    GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $iTreeView_2)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateTreeViewItem("Style", $iTreeView_2)
    
    
    GUISetState()
    While 1
     $msg = GUIGetMsg()
     Select
     Case $msg = $GUI_EVENT_CLOSE
     ExitLoop
     Case $msg = $buttonstart
     GUICtrlSetState($ani1, 1)
     Case $msg = $buttonstop
     GUICtrlSetState($ani1, 0)
     Case $msg = $buttonTab
     GUICtrlSetState($child1_tabitem1, $GUI_SHOW)
     Case $msg = $child1_tabitem1
     GUICtrlSetState($buttonTab, $GUI_HIDE)
     Case $msg = $child1_tabitem2
     GUICtrlSetState($buttonTab, $GUI_SHOW)
     Case $msg = $okbutton
     $lable3 = GUICtrlCreateLabel("0", 70, 322, 20, 20)
     GUICtrlSetColor($lable3, $GUI_BKCOLOR_TRANSPARENT)
     $i = 0
     While($i < 99)
     GUICtrlSetData($progress_bar, $i)
     $i += 0.01
     GUICtrlSetData($lable3, GUICtrlRead($progress_bar))
     WEnd
     case $msg = $cancelbutton
     GUICtrlSetData($item2, "||COL"&Random(10,100,1))
     Case $msg = $Watir_Test_button
     run("D:Ruby193in
    uby.exe C:UserschenpassionDesktopabc.rb")
     Case $msg = $GUI_Automation_Test
     Run("notepad.exe")
     WinWait("[CLASS:Notepad]")
     $winhandle = WinGetHandle("[class:Notepad]")
     ConsoleWrite($winhandle & @LF)
     $handle = ControlGetHandle($winhandle,"","Edit1")
     ConsoleWrite($handle & @LF)
     ControlSetText($winhandle,"",$handle,"GUI automation is going on")
     EndSelect
    WEnd
  • 相关阅读:
    CentOS6.5安装Scrapy
    CentOS6.5安装pip
    CentOS6.5 安装openssl
    curl不能支持https问题
    pip安装时遇到的问题集锦,持续更新!
    CentOS6.5安装python3.7
    IntelliJ IDEA 17 本地LicenseServer激活
    omnidb数据库web管理工具安装
    CentOS7安装Kubernetes1.18.1并使用flannel
    Portainer中文汉化
  • 原文地址:https://www.cnblogs.com/autotest/p/3262386.html
Copyright © 2011-2022 走看看