drjgk44268 2019-07-04 05:01
浏览 368
已采纳

如何将我的变量存储在yaml文件中?

I have just started to learn Selenium Testing in Php and I started to test login function in the website. I would like to write standard test which is applicable for any website. That's why I would like to keep my variables in separate YML file.

How can keep my variables in YML file and call my variables from YML file to php? I have tried too many solution but none of them really worked. Thanks in advance for your help.

class OrderCest
{
    public static $URL = '/';
    public static $searchField = '#login--form #email';
    public static $passwordField = '#login--form input[name=password]';
    public static $loginButton = '#login--form button[type=submit]';

    public function checkLogin(AcceptanceTester $I)
    {
        $I->amOnPage($URL);
        $I->fillField(self::$emailField, $email);
        $I->fillField(self::$passwordField, $password);
        $I->click(self::$loginButton);
        sleep(3);
        return $this;
    }

my Codeception configuration is:

actor: AcceptanceTester
modules:
    enabled:
        - \Helper\Acceptance
        - WebDriver:
            url: '/'
            browser: chrome
            host: '787877878'
            window_size: 1920x1080
            port: 9999
            wait: 5
            capabilities:
                unexpectedAlertBehaviour: 'accept'
      setting:
        email: 'testdeneyv@gmail.com'
        pasword: ................

展开全部

  • 写回答

1条回答 默认 最新

  • douqun1977 2019-07-04 06:31
    关注

    If you want to use YAML in PHP, you need to install the extension with PECL:

    pecl install yaml
    

    If it fails with a libtool version mismatch error, you will need to download it first, compile and install it yourself, and enable it in the php.ini file.

    Once that's done, you can easily parse your file by getting its content and running the parse function, like so:

    $vars = yaml_parse( file_get_contents( './vars.yml' ) );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部