簡體   English   中英

鏈接webdriver方法

[英]Chaining webdriver methods

我想實現一個類來執行一些常見的webdriver函數,但我不斷得到: 驅動程序服務器已經死了。

像這樣的東西:

class mywebdriver {

    function __construct( $args ){

        //options
        $options = new ChromeOptions();
        $options->addArguments($args);

        //capabilities
        $caps = DesiredCapabilities::chrome();
        $caps->setCapability(ChromeOptions::CAPABILITY, $options);
        $driver = ChromeDriver::start($caps);
        $driver->manage()->timeouts()->implicitlyWait = 20;

        $this->driver = $driver;    
    }

    function login(){       
        //all things related to logging into a site using $this->driver
        $this->driver->get( "www.url.com" );
    }

    function logout(){      
        //all things related to logging into a site using $this->driver
        $this->driver->quit();
    }

    function search( $value ){      
        //enter a value in the search field and print results
    }

    ... other methods
}

然后,鏈接方法,例如:

$drive = new mywebdriver();
try {
    $drive->login()
        ->search( "toyota" )
        ->search( "ford" )
        ->logout();
} catch (Exception $e) {
    echo "Caught Exception". $e->getMessage();
}

這是典型的,也可能嗎? 我已經嘗試了一些東西,但驅動程序服務器一直給我“死”的例外。

要實現方法鏈模式,只需返回實例:

public function search( $value ) : mywebdriver
{      
    //enter a value in the search field and print results
    return $this;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM