我正在尝试使用Behat/Mink在我的Drupal网站上测试条纹。
我有一个Stripe测试支付网关配置。我的
我的FeatureContext.php看起来是这样的:
/**
* @Then I enter my US JCB credit card info
*/
public function iEnterMyUsJcbCreditCardInfo() {
$this->enterCardDetails('3566 0020 2036 0505', '11 / 21', '777');
}
private function enterCardDetails($card_number, $exp_date, $cvc) {
$this->getSession()->wait(2000);
// Switch to the payment iframe.
$this->getSession()->switchToIFrame(self::STRIPE_CARDNO_IFRAME);
$this->getSession()->wait(1000);
$this->fillField('cardnumber', "$card_number");
$this->getSession()->wait(2000);我添加了wait(),因为信用卡号码填错了。
例如,当我有步骤And I enter my US JCB credit card info时,我得到的不是正确的测试卡号(3566002020360505),而是3566 0000 3605 5022。

不正确的卡号不一致;当我三次运行测试时,我得到了以下数字:
因此,stripe.js似乎干扰了我的信用卡号码输入。
信用卡过期日期和CVC/安全代码输入没有此问题。
当我去掉信用卡号码中的空格时,我仍然会遇到同样的问题(在输入过程中,这个数字会被随机混淆)。
即使我将卡号输入前后的等待时间设置为5秒,卡号仍然会被混淆。
我怎样才能输入白帽/水貂的信用卡号码而不乱码?
发布于 2020-11-07 03:39:00
摘要:你必须一次输入一个数字的信用卡号码,因为如果你一次全部输入的话,Stripe.js会把它的间距搞砸。
以下是我在过去几周使用的相关代码:
// Handle randomized iframe numbers by targeting the div above them.
const STRIPE_CARDNO_IFRAME = 'card-number-element';
const STRIPE_EXP_IFRAME = 'expiration-element';
const STRIPE_CVC_IFRAME = 'security-code-element';
/**
* @Then I enter my credit card number :cc_number
*/
public function iEnterMyCreditCardNumber($cc_number) {
$payment_errors_element = $this->getSession()->getPage()->find('css', 'div#payment-errors');
if ($payment_errors_element->getText()) {
throw new Exception($payment_errors_element->getText());
}
echo "Test credit card number: $cc_number\n";
$this->switchToMyIframe(self::STRIPE_CARDNO_IFRAME);
$this->getSession()->wait(5000);
$credit_card_field = $this->getSession()->getPage()->findField('cardnumber');
$cc_number_nospaces = str_replace(' ', '', "$cc_number");
$creditcard_singledigits = str_split("$cc_number_nospaces", 1);
foreach ($creditcard_singledigits as $creditcard_singledigit) {
$this->getSession()->wait(2000);
$credit_card_field->sendKeys("$creditcard_singledigit");
}
// Take a screenshot for debugging when the card number is entered incorrectly.
$this->saveScreenshot();
$this->getSession()->switchToIFrame(null);
}
/*
* Helper function to find the iframe.
*/
private function switchToMyIframe($selector) {
$iframe_selector = "div#$selector iframe";
$iframe = $this->getSession()->getPage()->find('css', $iframe_selector);
$iframe_name = $iframe->getAttribute('name');
echo "Switching to iframe $iframe_name\n";
$this->getSession()->switchToIFrame("$iframe_name");
}发布于 2020-09-14 02:35:08
我对behat或mink一无所知,但我建议您删除这些空格;它们看起来都包含相同的数字,只是顺序不同,所以这些空格可能会引起问题,因为光标可能会移动一点。
https://stackoverflow.com/questions/63862931
复制相似问题