Passed
Pull Request — master (#4)
by Raúl
02:29
created

AbstractBuy::goToPagantis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Test\Buy;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverExpectedCondition;
7
use Test\PagantisOscommerceTest;
8
9
/**
10
 * Class AbstractBuy
11
 * @package Test\Buy
12
 */
13
abstract class AbstractBuy extends PagantisOscommerceTest
14
{
15
    /**
16
     * Product name
17
     */
18
    const PRODUCT_NAME = 'Matrox G200 MMS';
19
20
    /**
21
     * Correct purchase message
22
     */
23
    const CORRECT_PURCHASE_MESSAGE = 'YOUR ORDER HAS BEEN RECEIVED.';
24
25
    /**
26
     * Canceled purchase message
27
     */
28
    const CANCELED_PURCHASE_MESSAGE = 'YOUR ORDER HAS BEEN CANCELED.';
29
30
    /**
31
     * Shopping cart message
32
     */
33
    const SHOPPING_CART_MESSAGE = 'SHOPPING CART';
34
35
    /**
36
     * Empty shopping cart message
37
     */
38
    const EMPTY_SHOPPING_CART = 'SHOPPING CART IS EMPTY';
39
40
    /**
41
     * Pagantis Order Title
42
     */
43
    const PAGANTIS_TITLE = 'Paga+Tarde';
44
45
    /**
46
     * Notification route
47
     */
48
    const NOTIFICATION_FOLDER = '/pagantis/notify';
49
50
    /**
51
     * Buy unregistered
52
     */
53
    public function prepareProductAndCheckout()
54
    {
55
        $this->goToProductPage();
56
        $this->addToCart();
57
    }
58
59
    /**
60
     * testAddToCart
61
     */
62
    public function addToCart()
63
    {
64
        $addToCartButtonSearch = WebDriverBy::id('tdb4');
65
        $condition = WebDriverExpectedCondition::visibilityOfElementLocated($addToCartButtonSearch);
66
        $this->waitUntil($condition);
67
        $addToCartButtonElement = $this->webDriver->findElement($addToCartButtonSearch);
68
        $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($addToCartButtonElement));
69
        $addToCartButtonElement->click();
70
71
72
        $buyButtonSearch = WebDriverBy::id('tdb5');
73
        $condition = WebDriverExpectedCondition::visibilityOfElementLocated($buyButtonSearch);
74
        $this->waitUntil($condition);
75
        $buyButtonElement = $this->webDriver->findElement($buyButtonSearch);
76
        $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buyButtonElement));
77
        $buyButtonElement->click();
78
    }
79
80
    /**
81
     * Go to the product page
82
     */
83
    public function goToProductPage()
84
    {
85
        $this->webDriver->get(self::OSCURL);
86
        $productGridSearch = WebDriverBy::className('contentText');
87
        $productLinkSearch = $productGridSearch->linkText(strtoupper(self::PRODUCT_NAME));
88
89
        $this->webDriver->wait()->until(
90
            WebDriverExpectedCondition::elementToBeClickable(
91
                $productLinkSearch
92
            )
93
        );
94
        $productLinkElement = $this->webDriver->findElement($productLinkSearch);
95
        $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($productLinkElement));
96
        sleep(3);
97
        $productLinkElement->click();
98
        $this->assertSame(
99
            self::PRODUCT_NAME . ', ' . self::TITLE,
100
            $this->webDriver->getTitle()
101
        );
102
    }
103
104
    /**
105
     * Fill the shipping method information
106
     */
107
    public function fillPaymentMethod()
108
    {
109
        sleep(5);
110
111
        $reviewStepSearch = WebDriverBy::id('p_method_pagantis');
112
        $this->webDriver->wait()->until(
113
            WebDriverExpectedCondition::elementToBeClickable($reviewStepSearch)
114
        );
115
        $this->findById('p_method_pagantis')->click();
116
117
        $this->webDriver->executeScript("payment.save()");
118
        $reviewStepSearch = WebDriverBy::id('review-buttons-container');
119
        $this->webDriver->wait()->until(
120
            WebDriverExpectedCondition::visibilityOfElementLocated($reviewStepSearch)
121
        );
122
123
        $this->assertTrue(
124
            (bool) WebDriverExpectedCondition::visibilityOfElementLocated($reviewStepSearch)
125
        );
126
    }
127
128
    /**
129
     * Fill the shipping method information
130
     */
131
    public function fillShippingMethod()
132
    {
133
        sleep(5);
134
135
        $this->findById('s_method_flatrate_flatrate')->click();
136
        $this->webDriver->executeScript('shippingMethod.save()');
137
138
        $checkoutStepPaymentMethodSearch = WebDriverBy::id('checkout-payment-method-load');
139
        $this->webDriver->wait()->until(
140
            WebDriverExpectedCondition::visibilityOfElementLocated($checkoutStepPaymentMethodSearch)
141
        );
142
        $this->assertTrue(
143
            (bool) WebDriverExpectedCondition::visibilityOfElementLocated($checkoutStepPaymentMethodSearch)
144
        );
145
    }
146
147
148
    /**
149
     * Complete order and open Pagantis (redirect or iframe methods)
150
     *
151
     * @throws \Facebook\WebDriver\Exception\NoSuchElementException
152
     * @throws \Facebook\WebDriver\Exception\TimeOutException
153
     */
154
    public function goToPagantis()
155
    {
156
        sleep(5);
157
158
        $this->webDriver->executeScript('review.save()');
159
    }
160
161
    /**
162
     * Close previous pagantis session if an user is logged in
163
     *
164
     * @throws \Facebook\WebDriver\Exception\NoSuchElementException
165
     * @throws \Facebook\WebDriver\Exception\TimeOutException
166
     */
167
    public function logoutFromPagantis()
168
    {
169
        // Wait the page to render (check the simulator is rendered)
170
        $this->webDriver->wait()->until(
171
            WebDriverExpectedCondition::elementToBeClickable(
172
                WebDriverBy::name('minusButton')
173
            )
174
        );
175
        // Check if user is logged in in Pagantis
176
        $closeSession = $this->webDriver->findElements(WebDriverBy::name('one_click_return_to_normal'));
177
        if (count($closeSession) !== 0) {
178
            //Logged out
179
            $continueButtonSearch = WebDriverBy::name('one_click_return_to_normal');
180
            $continueButtonElement = $this->webDriver->findElement($continueButtonSearch);
181
            $continueButtonElement->click();
182
        }
183
    }
184
185
    /**
186
     * Verify That UTF Encoding is working
187
     */
188
    public function verifyUTF8()
189
    {
190
        $paymentFormElement = WebDriverBy::className('FieldsPreview-desc');
191
        $condition = WebDriverExpectedCondition::visibilityOfElementLocated($paymentFormElement);
192
        $this->webDriver->wait()->until($condition);
193
        $this->assertTrue((bool) $condition);
194
        $this->assertSame(
195
            $this->configuration['firstname'] . ' ' . $this->configuration['lastname'],
196
            $this->findByClass('FieldsPreview-desc')->getText()
197
        );
198
    }
199
200
    /**
201
     * Check if the purchase was in the myAccount panel and with Processing status
202
     *
203
     * @param string $statusText
204
     *
205
     * @throws \Facebook\WebDriver\Exception\NoSuchElementException
206
     * @throws \Facebook\WebDriver\Exception\TimeOutException
207
     */
208
    public function checkLastPurchaseStatus($statusText = 'Processing')
209
    {
210
        $accountMenu = WebDriverBy::cssSelector('.account-cart-wrapper a.skip-link.skip-account');
211
        $this->clickElement($accountMenu);
0 ignored issues
show
Bug introduced by
The method clickElement() does not exist on Test\Buy\AbstractBuy. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

211
        $this->/** @scrutinizer ignore-call */ 
212
               clickElement($accountMenu);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
212
213
        $myAccountMenu = WebDriverBy::cssSelector('#header-account .first a');
214
        $this->clickElement($myAccountMenu);
215
216
        $this->webDriver->wait()->until(
217
            WebDriverExpectedCondition::visibilityOfElementLocated(
218
                WebDriverBy::cssSelector('.box-account.box-recent')
219
            )
220
        );
221
222
        $status = $this->findByCss('.box-account.box-recent .data-table.orders .first .status em')->getText();
223
        $this->assertTrue(($status == $statusText));
224
    }
225
226
    /**
227
     * Check purchase return message
228
     *
229
     * @param string $message
230
     *
231
     * @throws \Facebook\WebDriver\Exception\NoSuchElementException
232
     * @throws \Facebook\WebDriver\Exception\TimeOutException
233
     */
234
    public function checkPurchaseReturn($message = '')
235
    {
236
        // Check if all goes good
237
        $this->webDriver->wait()->until(
238
            WebDriverExpectedCondition::visibilityOfElementLocated(
239
                WebDriverBy::cssSelector('.page-title h1')
240
            )
241
        );
242
        $successMessage = $this->findByCss('.page-title h1');
243
        $this->assertContains(
244
            $message,
245
            $successMessage->getText()
246
        );
247
    }
248
}