/** * Retrieve an instance of block * * @param string $blockName * @return BlockInterface * @throws \InvalidArgumentException */ public function getBlockInstance($blockName) { if (!isset($this->blockInstances[$blockName])) { $blockMeta = isset($this->blocks[$blockName]) ? $this->blocks[$blockName] : []; $class = isset($blockMeta['class']) ? $blockMeta['class'] : false; if ($class) { $element = $this->_browser->find($blockMeta['locator'], $blockMeta['strategy']); $config = ['renders' => isset($blockMeta['renders']) ? $blockMeta['renders'] : []]; $block = $this->_blockFactory->create($class, ['element' => $element, 'config' => $config]); } else { throw new \InvalidArgumentException(sprintf('There is no such block "%s" declared for the page "%s" ', $blockName, $class)); } $this->blockInstances[$blockName] = $block; } // @todo fix to get link to new page if page reloaded return $this->blockInstances[$blockName]->reinitRootElement(); }
/** * Method to add new tax rate * * @param TaxRule $taxRule * @return void */ protected function addNewTaxRates($taxRule) { $taxRateBlock = $this->_rootElement->find($this->taxRateBlock, Locator::SELECTOR_CSS, 'multiselectlist'); /** @var \Magento\Tax\Test\Block\Adminhtml\Rule\Edit\TaxRate $taxRateForm */ $taxRateForm = $this->blockFactory->create('Magento\\Tax\\Test\\Block\\Adminhtml\\Rule\\Edit\\TaxRate', ['element' => $this->browser->find($this->taxRateForm, Locator::SELECTOR_XPATH)]); /** @var \Magento\Tax\Test\Fixture\TaxRule\TaxRate $taxRatesFixture */ $taxRatesFixture = $taxRule->getDataFieldConfig('tax_rate')['source']; $taxRatesFixture = $taxRatesFixture->getFixture(); $taxRatesData = $taxRule->getTaxRate(); foreach ($taxRatesData as $key => $taxRate) { $option = $taxRateBlock->find(sprintf($this->optionMaskElement, $taxRate), Locator::SELECTOR_XPATH); if (!$option->isVisible()) { $taxRate = $taxRatesFixture[$key]; $this->clickAddNewButton($taxRateBlock); $taxRateForm->fill($taxRate); $taxRateForm->saveTaxRate(); /** @var \Magento\Tax\Test\Fixture\TaxRate $taxRate */ $code = $taxRate->getCode(); $this->waitUntilOptionIsVisible($taxRateBlock, $code); } } }