Application::run()   A
last analyzed

Complexity

Conditions 5
Paths 66

Size

Total Lines 50
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 2 Features 0
Metric Value
cc 5
eloc 36
c 6
b 2
f 0
nc 66
nop 1
dl 0
loc 50
rs 9.0328
1
<?php
2
3
namespace Pagantis\SeleniumFormUtils\Step;
4
5
use Facebook\WebDriver\WebDriverBy;
6
7
/**
8
 * Class Application
9
 *
10
 * @package Pagantis\SeleniumFormUtils\Step
11
 */
12
class Application extends AbstractStep
13
{
14
    /**
15
     * Handler step
16
     */
17
    const STEP = 'Application';
18
19
    const VALID_CARD_NUMBER = '4111111111111111';
20
21
    const REJECTED_CARD_NUMBER = '4012888888881881';
22
23
    const CARD_CVC = '123';
24
25
    const CARD_HOLDER = 'John Doe';
26
27
    /**
28
     * Pass from confirm-data to next step in Application Form
29
     *
30
     * @param bool $rejected
31
     * @return bool
32
     * @throws \Exception
33
     */
34
    public function run($rejected = false)
35
    {
36
        $this->validateStep(self::STEP);
37
38
        try {
39
            $iframe = $this->webDriver->findElement(WebDriverBy::tagName('iframe'));
40
            $iFrameOneId = $iframe->getAttribute('name');
41
            $spreedlyCode = explode('-', $iFrameOneId);
42
            $iFrameTwoId = 'spreedly-cvv-frame-'.end($spreedlyCode);
43
44
            //CVV IFRAME
45
            $this->moveToParent();
46
            $this->moveToIFrame($iFrameTwoId);
47
            $cvv = $this->webDriver->findElement(WebDriverBy::id('cvv'));
48
            $cvv->clear()->sendKeys(self::CARD_CVC);
49
            $this->moveToParent();
50
51
            //CARD IFRAME
52
            $this->moveToIFrame($iFrameOneId);
53
            $messageElementSearch = WebDriverBy::id('card_number');
54
            sleep(2);
55
56
            $cardNumberIframe = $this->webDriver->findElement($messageElementSearch);
57
            if ($cardNumberIframe!='') {
0 ignored issues
show
introduced by
The condition $cardNumberIframe != '' is always true.
Loading history...
58
                $cardNumberStyle = $cardNumberIframe->getAttribute('style');
59
            }
60
61
            if (strpos($cardNumberStyle, "display: none")===false) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $cardNumberStyle does not seem to be defined for all execution paths leading up to this point.
Loading history...
62
                $this->waitTobeVisible(WebDriverBy::id('card_number'));
63
                $creditCardNumber = $this->webDriver->findElement(WebDriverBy::name('card_number'));
64
                $card             = $rejected ? self::REJECTED_CARD_NUMBER : self::VALID_CARD_NUMBER;
65
                $creditCardNumber->clear()->sendKeys($card);
66
                $this->moveToParent();
67
                sleep(1);
68
                $fullName = $this->webDriver->findElement(WebDriverBy::name('fullName'));
69
                $fullName->clear()->sendKeys(self::CARD_HOLDER);
70
                $expirationDate = $this->webDriver->findElement(WebDriverBy::name('expirationDate'));
71
                $expirationDate->clear()->sendKeys('1221');
72
            }
73
74
            $this->moveToParent();
75
            sleep(1);
76
        } catch (\Exception $exception) {
77
            unset($exception);
78
            return false;
79
        }
80
81
        $formContinue = $this->webDriver->findElement(WebDriverBy::name('continue_button'));
82
        $formContinue->click();
83
        return true;
84
    }
85
}
86