使用AppleScript进行简单的自动化测试(四)

  AppleScript的实际应用

 

  1.连接网络:在做自动化测试有时需要从服务器上下载build,那么我们需要连接网络  

mount volume "smb://xx.xx.xx.xx/xx/xx" as user name "userName" with password "password"

  连接成功后,会在xx‘s Mac 下看到映射的地址.

 

  2.launch 程序:

    1>dmg:    

tell application "Finder"
  open document file "System:Users:zzz:Desktop:xx.dmg"

    2>app:

launch application "System:Users:zzz:Desktop:Accessibility Inspector.app"

 

  3.打开URL:进入百度首页

open location "http://www.baidu.com"

   

  4.获取第一个窗体的process name  

set frontApp to name of first application process whose frontmost is true

  

  5.获取所有可见app的process name 

set visibleApps to application process whose visible is true

 

  6.获取随机数

random number from 1 to 4

 

  7.时间

tell application "System Events"
    set tmpDate to (current date)
  
    get seconds of tmpDate  --秒

    get minutes of tmpDate  --分

             get hours of tmpDate     --时

    get day of tmpDate         --天

    get month of tmpDate     --月

    get year of tmpDate        --年

    time string of tmpDate     --当前时间:4:58:09 PM

    date string of tmpDate     --Wednesday, February 19, 2014
    
   实现datediff功能(返回second)
    set StartTime to current date
    delay 2
    get (current date) - StartTime
end tell        

 

  8.字符串:

    Split方法    

on Split(delimiter, splitString)
    tell application "System Events"
        set AppleScripts text item delimiters to delimiter
        set aa to every text item of splitString
    end tell
end Split

 

    Replace方法    

on Replace(repalceString, oldString, newString)
    tell application "System Events"
        set AppleScripts text item delimiters to oldString
        set aa to every text item of repalceString
        set AppleScripts text item delimiters to newString
        set bb to aa as string
    end tell
end Replace

 

 

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。