2012-10-23 34 views
3

我使用Selenium WebDriver和firefox。每次硒在临时文件夹中生成firefox的新anoniumus配置文件并退出后,将其删除。我需要这个配置文件。我怎么才能得到它? F.e.个人资料存储在保存由Selenuim Web Driver生成的firefox配置文件

C:\Documents and Settings\Developer\Local Settings\Temp\anonymous5583304190515426768webdriver-profile 

关停的webdriver与

driver.quit(); 

档将被移除后,但它已经登录,我想用它的下一次迭代,用它INITING的webdriver:

FirefoxDriver driver = new FirefoxDriver(new FirefoxProfile(profileFolder)); 

是否有可能保存配置文件没有肮脏的黑客,如应付整个文件夹,而驱动程序工程(我不知道它甚至可以工作,因为在windows中,文件夹被锁定,而Firefox启动时)?在Selenium中可能存在一些API吗?

回答

2

为什么不只是改变方法?

  • Create firefox profile这将是干净的,并以某种方式命名你知道它是什么。例如SELENIUM
  • 初始化时的webdriver:

    ProfilesIni allProfiles = new ProfilesIni(); 
    FirefoxProfile desiredProfile = allProfiles.getProfile("SELENIUM"); 
    WebDriver driver = new FirefoxDriver(desiredProfile); 
    

这样,你确保这个配置文件将被任何时间使用你做的测试...

+0

不幸的是,硒副本从输入配置文件数据到anonymous5583304190515426768webdriver-profile这样的时态配置文件中,因此所有的cookie都会在其中(并且在测试关机后被删除)。 – rdo

+2

@rdo只需查找'profile.path值',就可以取回该tmp配置文件。使用python绑定的示例http://stackoverflow.com/a/33350778/2480481 – erm3nda