如何在不为每个功能运行新的浏览器窗口的情况下运行PHPUnit Selenium测试? [英] How do I run a PHPUnit Selenium test without having a new browser window run for each function?

查看:57
本文介绍了如何在不为每个功能运行新的浏览器窗口的情况下运行PHPUnit Selenium测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHPUnit运行硒测试用例.我要做的第一件事就是尝试登录功能,它可以完美运行,但是我想运行一个功能来检查登录后页面上的信息,但是它会打开一个新的浏览器,而不是在当前浏览器窗口中继续.这是一个问题的原因是因为该页面设置为在关闭窗口时删除登录身份验证,因此如果您使用$ this-> url()转到该页面,则会出现我需要登录的错误.这是我现在的代码,它启动浏览器并运行测试登录表单的功能,然后关闭浏览器,打开一个新的浏览器并运行链接检查.当然,由于关闭窗口,因此由于身份验证错误而导致错误.我可以在一个函数中运行所有测试,但这确实是草率的编码,我想避免这种情况.有人知道如何解决这个问题吗?

I am trying to run a selenium test case using PHPUnit. And the first thing I do is trying the login function, this works perfect but then I want to run a function to check information on the page following the login but it opens a new browser instead of continuing in the current browser window. The reason this is a problem is because the page is setup to remove login authentication when the window is closed so if you use $this->url() to go to the page it gives the error that I need to login. This is my code right now, It starts the browser and runs the function to test the login form, then it closes the browser, open a new one and run the link check. This of course results in an error due to the authentication error because the window was closed. I could run all the tests in one function but that is really sloppy coding and I want to avoid this. Anyone know how to solve this?

<?php
    class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase {
        public function setUp()
        {
            $this->setBrowser("firefox");
            $this->setBrowserUrl("https://**************************");
        }

        public function testLoginForm()
        {

            $this->url("login.php");
            $this->byLinkText('Forgot your password?');
            $form = $this->byCssSelector('form');
            $this->byName('username')->value('test');
            $this->byName('password')->value('1234');
            $form->submit();
        }


        public function testCheckForMainMenueLinks ()
        {
            $this->url("index.php");
            $this->byLinkText('Home');
            $this->byLinkText('Products');
            $this->byLinkText('About us');
            $this->byLinkText('Contact');
        }
    }
?>

推荐答案

好吧,我想您可以直接从另一个函数中调用该函数,如下所示:

Okej so I guess you can just call the function directly from another function like so:

public function testOne
{
#code
$this->Two();
}

public function Two()
{
#code
$this->Three();
}

public function Three()
{
#code
}

,依此类推,它将在没有新浏览器的情况下运行下一个功能,但是,如果在任何测试中的任何地方失败,则整个测试将停止,因此反馈将不如单个测试好.

and so on, this will just run the next function without a new browser, however, if it fails anywhere in any test the whole test is stoped so the feedback wont bee as good as individual tests.

这篇关于如何在不为每个功能运行新的浏览器窗口的情况下运行PHPUnit Selenium测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆