【问题标题】:How To Automate Teamwork Backup Download如何自动化团队合作备份下载
【发布时间】:2015-06-25 19:47:38
【问题描述】:

我正在尝试自动下载由Teamwork 创建的备份文件。它的工作方式是您登录,然后转到加载动态生成的 iframe 的页面,其中包含 src="https://tw-backup.teamwork.com/ext.cfm?backupaction=downloadLatestMySQLBackup"。

我已经尝试从 iframe 中获取实际链接,但我还没有让它工作。但是,如果我在浏览器中输入截断的链接,我使用的链接似乎可以工作。所以我只是想直接打开它。

不幸的是,它似乎挂了。

编辑

phantomjs --version = 1.9.8;

收到此错误:

[debug] [phantom] url changed to "https://tw-backup.teamwork.com/ext.cfm?backupa
ction=downloadLatestMySQLBackup"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Done 8 steps in 3427ms
finished
Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/Users/Brad/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap
.js. Domains, protocols and ports must match.

那么问题是我尝试访问的子域与我从哪里开始访问不同的子域吗?

如果您对此问题感兴趣,可以免费试用 Teamwork。顺便说一句,我们很好地利用它进行项目管理。

var casper = require('casper').create();

casper.start('https://myco.teamwork.com/', function () {

    console.log("start");

    this.waitForSelector("input[name='userLogin']",
        function success() {
            this.sendKeys("input[name='userLogin']", "me@myco.org");
        },
        function fail() {
            test.assertExists("input[name='userLogin']");
        });
    this.waitForSelector("input[name='password']",
        function success() {
            this.sendKeys("input[name='password']", "somePassword");
            console.log("login successful");
        },
        function fail() {
            test.assertExists("input[name='password']");
            console.log("login failed");
        });

    this.thenOpen('https://tw-backup.teamwork.com/ext.cfm?backupaction=downloadLatestMySQLBackup');   

});

【问题讨论】:

  • 你有什么 PhantomJS 版本?请注册resource.errorpage.errorremote.messagecasper.page.onResourceTimeout 活动 (Example)。也许有错误。尝试使用 --ssl-protocol=any --ignore-ssl-errors=true 运行 CasperJS。
  • @ArtjomB。请查看编辑..
  • 那个“错误”(不安全的 JavaScript 尝试...)表明您使用的是 PhantomJS 1.9.8 而不是 1.9.2。 It's actually not an error, but only some string that is printed when CasperJS is exiting。我在您的问题中没有看到错误。如何验证第二个页面加载成功还是失败?
  • 对,它是 1.9.8(错字)。日志显示,“[debug] [phantom] url 更改为 tw-backup.teamwork.com/ext.cfm?backupa ction=downloadLatestMySQLBackup”。这不是意味着页面加载成功了吗?
  • 是的,确实如此,这就是为什么我要问加载后会执行哪些步骤以及如何验证它是否不起作用。

标签: javascript selenium selenium-webdriver phantomjs casperjs


【解决方案1】:

我最终通过迁移到 Selenium 并使用 Chrome 驱动程序实现了这一点;Firefox 驱动程序将无法工作,因为它会弹出一个保存对话框。

不幸的是,我没有让这项工作无头。我希望 HtmlUnitDriver 能工作。它仍然是可能的,但就我的目的而言,打开浏览器实际上是可以的。

请注意,您需要安装 Chrome webdriver。在 MAC 上,您只需将其放入 /usr/bin。在 Windows 上,使用 .jar 和 chromedriver.ext 创建一个文件夹。然后执行它:

C:\Program Files\teamworkbackup>java -Dwebdriver.chrome.driver=:"C:\Program files\teamworkdbackup\chromedriver.exe" -jar teamworkdbackup.jar

源代码:

package com.rhoads.teamwork.backup;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;


public class TeamworkBackup {

    public static void main(String[] args) throws Exception {

        WebDriver driver;

        String baseUrl;

        driver = new ChromeDriver();

        baseUrl = "https://myco.teamwork.com/index.cfm";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get(baseUrl + "/");
        Thread.sleep(4000);
        driver.findElement(By.id("password")).clear();
        driver.findElement(By.id("password")).sendKeys("superstrong");
        driver.findElement(By.id("userLogin")).clear();
        driver.findElement(By.id("userLogin")).sendKeys("someguy@example.com");
        driver.findElement(By.id("ordLoginSubmitBtn")).click();
        Thread.sleep(4000);
        driver.get("https://myco.teamwork.com/settings?display=export");
        Thread.sleep(4000);
        driver.switchTo().frame("backupFrame");
        Thread.sleep(4000);
        driver.findElement(By.linkText("Download")).click();
        Thread.sleep(4000);
        driver.quit();


    }
}

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2018-08-21
    • 2022-01-03
    • 2012-03-29
    • 2022-10-18
    • 1970-01-01
    相关资源
    最近更新 更多