<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
 * @Title("[NO TESTCASEID]: A Functional Cest")
 * @group functional
 * @Description("<h3>Test files</h3>verification/TestModule/Test/BasicFunctionalTest/BasicFunctionalTest.xml<br>")
 */
class BasicFunctionalTestCest
{
	/**
	 * @var bool
	 */
	private $isSuccess = false;

	/**
	  * @param AcceptanceTester $I
	  * @throws \Exception
	  */
	public function _before(AcceptanceTester $I)
	{
		$I->comment('[START BEFORE HOOK]');
		$I->amOnPage("/beforeUrl"); // stepKey: beforeAmOnPageKey
		$I->comment('[END BEFORE HOOK]');
	}

	/**
	  * @param AcceptanceTester $I
	  * @throws \Exception
	  */
	public function _after(AcceptanceTester $I)
	{
		$I->comment('[START AFTER HOOK]');
		$I->amOnPage("/afterUrl"); // stepKey: afterAmOnPageKey
		$I->comment('[END AFTER HOOK]');
		if ($this->isSuccess) {
			unlink(__FILE__);
		}
	}

	/**
	  * @param AcceptanceTester $I
	  * @throws \Exception
	  */
	public function _failed(AcceptanceTester $I)
	{
		$I->saveScreenshot(); // stepKey: saveScreenshot
	}

	/**
	 * @Severity(level = SeverityLevel::CRITICAL)
	 * @Features({"TestModule"})
	 * @Stories({"MQE-305"})
	 * @param AcceptanceTester $I
	 * @return void
	 * @throws \Exception
	 */
	public function BasicFunctionalTest(AcceptanceTester $I)
	{
		$I->comment("");
		$I->comment("");
		$I->comment("seeComment");
		$someVarDefinition = $I->grabValueFrom(); // stepKey: someVarDefinition
		$I->acceptPopup(); // stepKey: acceptPopupKey1
		$I->amOnPage("/test/url"); // stepKey: amOnPageKey1
		$I->appendField(".functionalTestSelector"); // stepKey: appendFieldKey1
		$I->attachFile(".functionalTestSelector", "testFileAttachment"); // stepKey: attachFileKey1
		$I->cancelPopup(); // stepKey: cancelPopupKey1
		$I->checkOption(".functionalTestSelector"); // stepKey: checkOptionKey1
		$I->click(".functionalTestSelector"); // stepKey: clickKey1
		$I->clickWithLeftButton(".functionalTestSelector"); // stepKey: clickWithLeftButtonKey1
		$I->clickWithRightButton(".functionalTestSelector"); // stepKey: clickWithRightButtonKey1
		$I->clickWithLeftButton("#element#element .200", 200, 300); // stepKey: clickWithLeftButtonKeyXY1
		$I->clickWithRightButton("#element .4123#element", 200, 300); // stepKey: clickWithRightButtonKeyXY1
		$I->closeTab(); // stepKey: closeTabKey1
		$I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true); // stepKey: conditionalClickKey1
		$I->deleteEntity("createKey1", "test"); // stepKey: deleteKey1
		$I->deleteEntityByUrl("/V1/categories{$grabbedData}"); // stepKey: deleteKey2
		$I->dontSee("someInput", ".functionalTestSelector"); // stepKey: dontSeeKey1
		$I->dontSeeCheckboxIsChecked(".functionalTestSelector"); // stepKey: dontSeeCheckboxIsCheckedKey1
		$I->dontSeeCookie("someInput"); // stepKey: dontSeeCookieKey1
		$I->dontSeeCurrentUrlEquals("/functionalUrl"); // stepKey: dontSeeCurrentUrlEqualsKey1
		$I->dontSeeCurrentUrlMatches("/[0-9]+/"); // stepKey: dontSeeCurrentUrlMatchesKey1
		$I->dontSeeElement(".functionalTestSelector"); // stepKey: dontSeeElementKey1
		$I->dontSeeElementInDOM(".functionalTestSelector"); // stepKey: dontSeeElementInDOMKey1
		$I->dontSeeInCurrentUrl("/functionalUrl"); // stepKey: dontSeeInCurrentUrlKey1
		$I->dontSeeInField(".functionalTestSelector"); // stepKey: dontSeeInFieldKey1
		$I->dontSeeInPageSource("Cosmo Kramer"); // stepKey: dontSeeInPageSourceKey1
		$I->dontSeeInPageSource("<p>Jerry Seinfeld</p>"); // stepKey: dontSeeInPageSourceKey2
		$I->dontSeeInPageSource("Cosmo Kramer"); // stepKey: dontSeeInPageSourceKey3
		$I->dontSeeInPageSource("<p>Jerry Seinfeld</p>"); // stepKey: dontSeeInPageSourceKey4
		$I->dontSeeInPageSource("foo"); // stepKey: dontSeeInPageSourceKey5
		$I->dontSeeInPageSource("<p>foo</p>"); // stepKey: dontSeeInPageSourceKey6
		$I->dontSeeInSource("Cosmo Kramer"); // stepKey: dontSeeInSourceKey1
		$I->dontSeeInSource("<p>Jerry Seinfeld</p>"); // stepKey: dontSeeInSourceKey2
		$I->dontSeeInTitle("someInput"); // stepKey: dontSeeInTitleKey1
		$I->dontSeeLink("someInput", "/functionalUrl"); // stepKey: dontSeeLinkKey1
		$I->dontSeeOptionIsSelected(".functionalTestSelector", "someInput"); // stepKey: dontSeeOptionIsSelectedKey1
		$I->doubleClick(".functionalTestSelector"); // stepKey: doubleClickKey1
		$I->dragAndDrop(".functionalTestSelector", ".functionalTestSelector2"); // stepKey: dragAndDropKey1
		$I->dragAndDrop(".functionalTestSelector", ".functionalTestSelector2", 100, 900); // stepKey: dragAndDropKey2
		$executeJSKey1 = $I->executeJS("someJSFunction"); // stepKey: executeJSKey1
		$I->fillField(".functionalTestSelector", "someInput"); // stepKey: fillFieldKey1
		$I->fillField(".functionalTestSelector", "0"); // stepKey: fillFieldKey2
		$date = new \DateTime();
		$date->setTimestamp(strtotime("Now"));
		$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
		$generateDateKey = $date->format("H:i:s");

		$date = new \DateTime();
		$date->setTimestamp(strtotime("Now"));
		$date->setTimezone(new \DateTimeZone("UTC"));
		$generateDateKey2 = $date->format("H:i:s");

		$getOtp = $I->getOTP(); // stepKey: getOtp
		$getOtpWithInput = $I->getOTP("someInput"); // stepKey: getOtpWithInput
		$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput"); // stepKey: grabAttributeFromKey1
		$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']); // stepKey: grabCookieKey1
		$grabCookieAttributesKey1 = $I->grabCookieAttributes("grabCookieAttributesInput", ['domain' => 'www.google.com']); // stepKey: grabCookieAttributesKey1
		$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl"); // stepKey: grabFromCurrentUrlKey1
		$grabMultipleKey1 = $I->grabMultiple(".functionalTestSelector"); // stepKey: grabMultipleKey1
		$grabTextFromKey1 = $I->grabTextFrom(".functionalTestSelector"); // stepKey: grabTextFromKey1
		$grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); // stepKey: grabValueFromKey1
		$magentoCli1 = $I->magentoCLI("maintenance:enable", 60, "\"stuffHere\""); // stepKey: magentoCli1
		$I->comment($magentoCli1);
		$magentoCli2 = $I->magentoCLI("maintenance:enable", 120, "\"stuffHere\""); // stepKey: magentoCli2
		$I->comment($magentoCli2);
		$magentoCli3 = $I->magentoCLISecret("config:set somePath " . $I->getSecret("someKey"), 60); // stepKey: magentoCli3
		$I->comment($magentoCli3); // stepKey: magentoCli3
		$magentoCli4 = $I->magentoCLISecret("config:set somePath " . $I->getSecret("someKey"), 120); // stepKey: magentoCli4
		$I->comment($magentoCli4); // stepKey: magentoCli4
		$cronAllGroups = $I->magentoCron("", 70); // stepKey: cronAllGroups
		$I->comment($cronAllGroups);
		$cronSingleGroup = $I->magentoCron("index", 70); // stepKey: cronSingleGroup
		$I->comment($cronSingleGroup);
		$cronMultipleGroups = $I->magentoCron("a b c", 70); // stepKey: cronMultipleGroups
		$I->comment($cronMultipleGroups);
		$I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1
		$I->maximizeWindow(); // stepKey: maximizeWindowKey1
		$I->moveBack(); // stepKey: moveBackKey1
		$I->moveForward(); // stepKey: moveForwardKey1
		$I->moveMouseOver(".functionalTestSelector"); // stepKey: moveMouseOverKey1
		$I->openNewTab(); // stepKey: openNewTabKey1
		$I->pause(true); // stepKey: pauseKey1
		$I->pressKey("#page", "a"); // stepKey: pressKey1
		$I->pressKey("#page", ['ctrl', 'a'],'new'); // stepKey: pressKey2
		$I->pressKey("#page", ['shift', '111'],'1','x'); // stepKey: pressKey3
		$I->pressKey("#page", ['ctrl',  'a'],\Facebook\WebDriver\WebDriverKeys::DELETE); // stepKey: pressKey4
		$I->reloadPage(); // stepKey: reloadPageKey1
		$I->resetCookie("cookieInput"); // stepKey: resetCookieKey1
		$I->resizeWindow(0, 0); // stepKey: resizeWindowKey1
		$I->scrollTo(".functionalTestSelector"); // stepKey: scrollToKey1
		$I->see("someInput", ".functionalTestSelector"); // stepKey: seeKey1
		$I->seeCheckboxIsChecked(".functionalTestSelector"); // stepKey: seeCheckboxIsCheckedKey1
		$I->seeCookie("someInput"); // stepKey: seeCookieKey1
		$I->seeCurrentUrlEquals("/functionalUrl"); // stepKey: seeCurrentUrlEqualsKey1
		$I->seeCurrentUrlMatches("/[0-9]+/"); // stepKey: seeCurrentUrlMatchesKey1
		$I->seeElement(".functionalTestSelector"); // stepKey: seeElementKey1
		$I->seeElementInDOM(".functionalTestSelector"); // stepKey: seeElementInDOMKey1
		$I->seeInCurrentUrl("/functionalUrl"); // stepKey: seeInCurrentUrlKey1
		$I->seeInField(".functionalTestSelector", "someInput"); // stepKey: seeInFieldKey1
		$I->seeInPageSource("Home Page"); // stepKey: seeInPageSourceKey1
		$I->seeInPageSource("<h1 class=\"page-title\">"); // stepKey: seeInPageSourceKey2
		$I->seeInPopup("someInput"); // stepKey: seeInPopupKey1
		$I->seeInSource("Home Page"); // stepKey: seeInSourceKey1
		$I->seeInSource("<h1 class=\"page-title\">"); // stepKey: seeInSourceKey2
		$I->seeInTitle("someInput"); // stepKey: seeInTitleKey1
		$I->seeLink("someInput", "/functionalUrl"); // stepKey: seeLinkKey1
		$I->seeNumberOfElements(".functionalTestSelector"); // stepKey: seeNumberOfElementsKey1
		$I->seeOptionIsSelected(".functionalTestSelector", "someInput"); // stepKey: seeOptionIsSelectedKey1
		$I->selectOption(".functionalTestSelector"); // stepKey: selectOptionKey1
		$I->selectMultipleOptions(".filter", ".option", ['opt1',  'opt2']); // stepKey: selectMultipleOpts1
		$I->setCookie("someInput", "someCookieValue"); // stepKey: setCookieKey1
		$I->switchToIFrame("someInput"); // stepKey: switchToIFrameKey1
		$I->switchToNextTab(); // stepKey: switchToNextTabKey1
		$I->switchToPreviousTab(); // stepKey: switchToPreviousTabKey1
		$I->switchToWindow(); // stepKey: switchToWindowKey1
		$I->typeInPopup("someInput"); // stepKey: typeInPopupKey1
		$I->uncheckOption(".functionalTestSelector"); // stepKey: uncheckOptionKey1
		$I->unselectOption(".functionalTestSelector", "someInput"); // stepKey: unselectOptionKey1
		$I->wait(30); // stepKey: waitKey1
		$I->waitForElement(".functionalTestSelector", 30); // stepKey: waitForElementKey1
		$I->waitForElementNotVisible(".functionalTestSelector", 30); // stepKey: waitForElementNotVisibleKey1
		$I->waitForElementVisible(".functionalTestSelector", 30); // stepKey: waitForElementVisibleKey1
		$I->waitForElementChange("#selector", function(\WebDriverElement $el) {return $el->isDisplayed();}, 10); // stepKey: waitForElementChangeKey1
		$I->waitForJS("someJsFunction", 30); // stepKey: waitForJSKey1
		$I->waitForText("someInput", 30, ".functionalTestSelector"); // stepKey: waitForText1
	}

	public function _passed(AcceptanceTester $I)
	{
		// Test passed successfully.
		$this->isSuccess = true;
	}
}