我需要在selenium脚本中添加一个sikulix脚本来执行selenium无法完成的任务。当我运行波纹管脚本时
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
private var player: AVPlayer!
@IBOutlet weak var videoUiViewOutlet: UIView!
override func viewDidLoad() {
super.viewDidLoad()
self.setupView()
}
private func setupView()
{
let path = URL(fileURLWithPath: Bundle.main.path(forResource: "clouds", ofType: "mp4")!)
let player = AVPlayer(url: path)
let newLayer = AVPlayerLayer(player: player)
newLayer.frame = self.videoUiViewOutlet.frame
self.videoUiViewOutlet.layer.addSublayer(newLayer)
newLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
player.play()
player.actionAtItemEnd = AVPlayer.ActionAtItemEnd.none
NotificationCenter.default.addObserver(self, selector: #selector(self.videoDidPlayToEnd(notification:)),
name: NSNotification.Name(rawValue: "AVPlayerItemDidPlayToEndTimeNotification"), object: player.currentItem)
NotificationCenter.default.addObserver(self, selector: #selector(enteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(enteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
}
@objc func videoDidPlayToEnd(notification: Notification)
{
let player: AVPlayerItem = notification.object as! AVPlayerItem
player.seek(to: .zero, completionHandler: nil)
}
@objc func enteredBackground() {
print("scope: enteredBackground")
player.pause()
}
@objc func enteredForeground() {
print("scope: enteredForeground")
player.play()
}
}
从正常或升高的CMD可以正常工作。但是当我从正常或升高的pycharm运行它时
C:\Sikulix\\runsikulix.cmd -r C:\Sikulix\Scritps\WorkFlow.sikuli
它不起作用,出现了以下错误。
from subprocess import PIPE,Popen,STDOUT
from pprint import pprint as pp
command = "C:\Sikulix\\runsikulix.cmd -r C:\Sikulix\Scritps\WorkFlow.sikuli"
process = Popen(command,stdout=PIPE,shell=True)
end = process.communicate()
pp(end)
我在其他IDE中尝试过。
在“ C:\ Sikulix \ Scritps \ WorkFlow.sikuli”内部,简单的悬停即可
我使用的是Python 3.7 SikuliX-1.1.3 Windows 10 x64 用户管理员, 用户帐户控制设置设置为最大。
编辑
我测试了os.system()命令,鼠标移动了一点,但停止了,并在控制台上阻止了上述错误信息,并提供了更多信息。
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
(b'+++ JAVA_HOME specified but not useable C:\\Program Files\\Java\\jdk1.8.0_1'
b'52\\bin\r\n+++ looking for Java in system path and then in standard places\r'
b'\n+++ running this Java\r\n+++ trying to run SikuliX\r\n+++ using: -Xms64'
b'M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar C:\\Sikuli'
b'x\\sikulix.jar -r C:\\Sikulix\\Scritps\\WorkFlow.sikuli\r\n[error] RobotDe'
b'sktop: checkMousePosition: should be L(960,540)@S(0)[0,0 1920x1080]\nbut '
b'after move is L(768,432)@S(0)[0,0 1920x1080]\nPossible cause in case you '
b'did not touch the mouse while script was running:\n Mouse actions are blo'
b'cked generally or by the frontmost application.\nYou might try to run the'
b' SikuliX stuff as admin.\r\n[error] RobotDesktop: checkMousePosition: shou'
b'ld be L(3600,675)@S(1)[2400,0 2400x1350]\nbut after move is L(5385,920)@S'
b'(2)[4800,0 2400x1350]\nPossible cause in case you did not touch the mouse'
b' while script was running:\n Mouse actions are blocked generally or by th'
b'e frontmost application.\nYou might try to run the SikuliX stuff as admin'
b'.\r\n[error] script [ C:\\Sikulix\\Scritps\\WorkFlow.sikuli ] stopped wit'
b'h error at line --unknown--\r\n[error] Error caused by: Traceback (most re'
b'cent call last):\n File "C:\\Sikulix\\Scritps\\WorkFlow.sikuli\\WorkFlow'
b'.py", line 1, in <module>\n doubleClick("WybierzPlik-1.PNG")\n Line 27'
b'61, in file Region.java\n\r\n\tat org.sikuli.script.Region.wait(Region.java:'
b'2761)\r\n\tat org.sikuli.script.Region.find(Region.java:2326)\r\n\tat org.'
b'sikuli.script.Region.getLocationFromTarget(Region.java:3220)\r\n\tat org.si'
b'kuli.script.Region.doubleClick(Region.java:3767)\r\n\tat org.sikuli.script.'
b'Region.doubleClick(Region.java:3752)\r\n\tat sun.reflect.NativeMethodAccess'
b'orImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.'
b'invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.inv'
b'oke(Unknown Source)\r\n\tat java.lang.reflect.Method.invoke(Unknown Source)'
b'\r\norg.sikuli.script.FindFailed: FindFailed: WybierzPlik-1.PNG: (75x19) i'
b'n S(0)[0,0 1920x1080] E:Y, T:3.0\n Line 2761, in file Region.java\n\n\r\n',
None)
Process finished with exit code 0
解决方案
好的,我发现工作方法不是很好的解决方案。 我在这里将所有用户的访问控制更改为完全访问控制(我懒得检查哪个用户需要它)