douhanxujiuji6098 2015-01-31 15:33
浏览 11
已采纳

如何在Codeception中使用SubmitForm()附加文件

I'm testing a form through the SubmitForm() function because the form uses javascript to cycle through each individual item.

example:

$I->submitForm('#form', array(
    'feet' => '1',
    'inches' => '2',

), 'submit');

This works fine but I'm having trouble with a file upload input.

$I->submitForm('#form', array(
    'feet' => '1',
    'inches' => '2',
    'file' => ???

 ), 'submit');

I tried sending an array to mimic the $_FILES array but that obviously isn't the right way to do it. Is this possible?

  • 写回答

1条回答 默认 最新

  • doushen9863 2015-04-10 08:54
    关注

    I've encountered this issue as well and the only way I can see around it is to manually fill the fields and the click the submit button.

    For example

    $I->fillField(['name' => 'name'], 'Test');
    $I->attachFile('input[name=photo]', 'test.jpg');
    $I->click('#formId button[type=submit]');
    $I->seeCurrentRouteIs('route.index');
    $I->see('Model has been updated.');
    

    You can store any test files in the Codeception tests/_data folder.

    This does work, but sadly doesn't help me in my current situation as I have a form which dynamically populates various select elements so I need to submitForm as I can't manually selectOption as the options are populated depending on other form completions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)