Selenium节点作为MacOS上的LaunchAgent

时间:2017-10-25 22:06:22

标签: selenium service safari macos-sierra

我在MacOS上运行selenium节点进行safari测试。 MacOS Sierra 10.12.6 硒3.6.0 Java 9.0.1 我已经配置MacOS登录帐户,永远不会入睡,所以safari会工作。 我已将selenium节点配置为LaunchAgent启动。 我像这样运行.sh

/Users/myuser/Library/LaunchAgents/selnode.plist

它拥有 myuser wheel 的权限755 我在<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>selnode</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/Users/myuser/selenium/run.sh</string> </array> <key>KeepAlive</key> <true/> <key>StandardOutPath</key> <string>>/Users/myuser/selenium/stdout.log</string> <key>StandardErrorPath</key> <string>/Users/myuser/selenium/stderr.log</string> <key>Debug</key> <true/> <key>UserName</key> <string>myuser</string> </dict> </plist>

中创建了 selnode.plist (644 myuser wheel
launchctl load -w /Users/myuser/Library/LaunchAgents/selnode.plist

我加载了

               <script>
                    function validateMyForm() {
                            var sEmail = $('.one-field-pardot-form-handler').val();
                            if ($.trim(sEmail).length == 0) {
                                event.preventDefault();
                                alert('Please enter valid email address.');
                                return false;

                            }

                            if (validateEmail(sEmail)) {

                            }

                            else {
                                event.preventDefault();
                                alert('Invalid Email Address. Please try again.');                          }
                    };

                    function validateEmail(sEmail) {
                        var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
                        if (filter.test(sEmail)) {
                            return true;
                        }
                        else {
                            return false;
                        }
                    }                                                  

                 </script>  

                 <form action="https://go.pardot.com/l/43312/2017-10-24/7dnr3n" method="post" onSubmit="return validateMyForm();" novalidate>

                    <input class="one-field-pardot-form-handler" maxlength="80" name="email" size="20" type="email" placeholder="Enter Email Address" required="required" />
                    <div style="position:absolute; left:-9999px; top: -9999px;">
                      <label for="pardot_extra_field">Comments</label>
                      <input type="text" id="pardot_extra_field" name="pardot_extra_field">
                    </div>

                    <button type="submit" name="submit">Submit</button>
                </form>

它的运行我可以看到这个过程,我可以看到它连接在selenium hub控制面板中。 但测试失败了。它无法与野生动物园相互作用。 我可以看到该流程以 root 运行。我认为它应该以 myuser 运行。 如果我手动运行 run.sh ,一切都很好。 如何让MacOS在其他用户权限下运行我的代理?

1 个答案:

答案 0 :(得分:0)

这是plist的最终版本

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>selnode</string>
    <key>ProgramArguments</key>
    <array>           
        <string>/Users/myuser/selenium/run.sh</string>       
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/myuser/selenium/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/myuser/selenium/stderr.log</string>
    <key>UserName</key>
    <string>myuser</string>
    <key>GroupName</key>
    <string>staff</string>
    <key>WorkingDirectory</key>
    <string>/Users/myuser/selenium</string>
</dict>
</plist>

我不是把它放在全球图书馆,而是放在 / Users / myuser / Library / LaunchAgents 中 我已将权限设置为 0600 。 文件的所有权适用于 myuser 员工,不适用于root