2017-04-05 117 views

回答

0

谢谢你们的响应,好像是没有办法的主屏幕可以推出,甚至java的机器人钥匙“命令+ shift + home“不起作用。

所以我不得不写一个苹果脚本,当被调用时会在模拟器中启动主屏幕。

它在这里

try 
    tell application "System Events" 

     if exists process "Simulator" then 
      tell process "Dock" 
       delay 2 
       set frontmost to true 
       activate 
       tell list 1 
        try 
         perform action "AXShowMenu" of UI element "Simulator" 
         delay 2 
         #click accssibilitytitle "Open" of menu item of menu1 -- up arrow 
         key code 126 -- up arrow 

         key code 126 -- up arrow 

         key code 126 -- up arrow 
         key code 126 -- up arrow 

         key code 126 -- up arrow 
         -- key code 125 -- down arrow     
         delay 2 
         key code 36 -- return key      
        on error errMsg 
         if errMsg contains "Simulator" then 
          log "Simulator is not present in the dock... To run the automation, add Simulator in the dock and try again!!!" 

          return 
         else 
          log errMsg 

          return 
         end if 
        end try 
       end tell 
      end tell 
     end if 


    end tell 
on error errMsg 
    log errMsg 

end try 

tell application "System Events" to tell process "Simulator" 
    tell menu bar item 5 of menu bar 1 
     delay 3 
     click 
     delay 5 
     click menu item "Home" of menu 1 
     delay 3 
    end tell 
end tell 

它能够通过对目前在被告席上的模拟器图标点击右键成功地将焦点模拟器,然后从“硬件”菜单中选择“家”(这是菜单5 )。

0

ios中存在一个限制。我们无法发送关键代码来按ios中的主页按钮,并且由于此限制,我们无法自动执行主页按钮。但在android中,我们可以使用关键代码实现这一点。在iOS自动化中,我们无法做到这一点。

0

在测试您的应用程序期间,您可以在后台运行您的应用程序并取回。

要做到这一点,你必须添加

protected IOSDriver iosDriver;

定义后,在后台

@Test 
@Description("Some Description") 
public void testSearchZeroResultAndHomeBack(){ 

    // run app in background for 5 seconds 
    iosDriver.runAppInBackground(5); 

    Assert.assertTrue(isTextDisplayedOnPage("0 ilan")); 
} 

//运行的应用程序,持续5秒

iosDriver.runAppInBackground(5);