Selenium浏览器窗口大小

use*_*840 2 php firefox selenium unit-testing laravel-5.1

我是使用硒的新手.我已经下载了Selenium Standalone Server并通过输入成功运行了它

java -jar selenium-server-standalone-2.14.0.jar
Run Code Online (Sandbox Code Playgroud)

进入命令行.

跑完之后

 phpunit.bat
Run Code Online (Sandbox Code Playgroud)

从命令行开始,我的所有测试都将按预期传递,除非我手动最大化在测试过程中自动打开的Firefox浏览器窗口.

当测试运行时,当Firefox浏览器窗口打开时,如果我在登录测试运行时没有最大化该窗口,那么该测试将失败并以某种方式重定向到我网站上的意外页面.如果我在测试完成之前最大化窗口,则按预期单击"登录"按钮,加载正确的页面,测试通过.

因此,我想知道是否有办法在某处更改设置,以便Firefox浏览器在测试运行时只打开最大化?

我已经用Google搜索并发现了一些可能有用的代码片段,但我不确定这段代码的PHP版本在哪里,或者在哪里为我正在使用的Selenium版本放置一些类似的代码(Selenium Standalone Server) ):

# repositioning and resizing browser window:
driver.manage.window.move_to(300, 400)
driver.manage.window.resize_to(500, 800)
driver.manage.window.maximize
Run Code Online (Sandbox Code Playgroud)

或者这是C#,但我需要PHP,不知道在哪里找到合适的代码或在哪里放置它:

driver.Manage().Window.Maximize();   
Run Code Online (Sandbox Code Playgroud)

以下是我的tests/SeleniumTest.php文件中登录Selenium测试的代码(使用Laracasts/Integrated):

<?php

use Laracasts\Integrated\Extensions\Selenium;
use Laracasts\Integrated\Services\Laravel\Application as Laravel;

class SeleniumTest extends Selenium
{
    use Laravel;
    /**
     * Tests to see if the login page loads
     */
    public function testToSeeIfLoginLoads()
    {
        $this->visit('/login')
            ->see('Login')->see('Email Address')->see('Password')
            ->type('myemail@email.com', 'email')->type('mypassword', 'password')
            ->waitForElement('log_in')
           ->click('log_in')
            ->waitForElement('table_summary')
            ->see('Complete Course Summary');
    }
Run Code Online (Sandbox Code Playgroud)

小智 6

我没有使用Laravel,我正在使用经典的phpunit + selenium RC和/或webdriver,这对我来说在两个实现上都有效,在打开url之后,如果我只想要这个用于特定的测试:

$this->open("/");
$this->getEval("window.resizeTo(1225, 996); window.moveTo(0,200);");
//or $this->windowMaximize();
Run Code Online (Sandbox Code Playgroud)

或者对于facebook-webdriver:

$this->driver->get('myurl/');
$this->driver->manage()->window()->setSize(new WebDriverDimension(1225, 996));
Run Code Online (Sandbox Code Playgroud)

如果你想要它用于所有测试,你应该找到setUp方法并把它放在那里.在您的情况下,对于特定测试,这应该工作:

$this->visit('/')
->session->window($this->session->window_handle())
->postSize(['height' => 996, 'width' => 1225]);
Run Code Online (Sandbox Code Playgroud)

使用情况的详细信息,在这里.