zoukankan      html  css  js  c++  java
  • 使用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.处理字符串:

      1>Split方法    

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

      2>Replace方法    

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

      

      3>Contain:判断字符串A是否包含字符串B  

    return “abc" contain "a"  --return true

      

    9.处理文件

      1>Read  

    tell application "System Events"
        try
            set fp to open for access file ((path to desktop as text) & "123.txt") -- ((path to desktop as text) & "123.txt")获取文件路径 
             set myText to read fp
            display dialog myText
        end try
        close access file ((path to desktop as text) & "123.txt")   --释放
    end tell

      2>Write

       try
            set fp to open for access file ((path to desktop as text) & "123.txt") with write permission
            set eof of fp to 0
            write "123" to fp starting at eof
        end try
        close access file ((path to desktop as text) & "123.txt")


      3>Append

        try
            set fp to open for access file ((path to desktop as text) & "123.txt") with write permission
            write "123" to fp starting at eof
        end try
        close access file ((path to desktop as text) & "123.txt")

      

        

     

     

  • 相关阅读:
    SQL Server 2017 左补齐
    Mac下面配置oh-my-ssh
    关于VSTS自动Build报错问题之Microsoft.Net.Compilers
    Angular5中提取公共组件之radio list
    Angular5中提取公共组件之checkbox list
    关于博客园开放API的授权问题解决
    记开发个人图书收藏清单小程序开发(十)DB开发——新增图书信息
    Keepalived + Nginx:负载均衡+高可用服务 --keepalived介绍及应用
    Nginx:综合架构负载均衡 -- nginx负载均衡企业实践应用
    Nginx:综合架构负载均衡 -- nginx负载均衡介绍部署及应用
  • 原文地址:https://www.cnblogs.com/Alvin-x/p/3555982.html
Copyright © 2011-2022 走看看