Crawler example

'id' => 'sdc-wrapper',
      ],
      'component' => $component,
    ];
    $metadata = $metadata ?: new BubbleableMetadata();
    $context = new RenderContext();
    $renderer = \Drupal::service('renderer');
    $output = $renderer->executeInRenderContext($contextfn () => $renderer->render($component));
    if (!$context->isEmpty()) {
      $metadata->addCacheableDependency($context->pop());
    }
    return new Crawler((string) $output);
  }

}
$context = $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        $controller = $this->getContainer()->get(ProductController::class);

        if ($shouldThrowException) {
            static::expectException(ProductNotFoundException::class);
        }

        $response = $controller->index($context$this->createDetailRequest($context$this->ids->get($requestVariant)));

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());

        $crawler = new Crawler();
        $crawler->addHtmlContent((string) $response->getContent());

        $blueFound = false;
        $greenFound = false;
        $redFound = false;
        $xlFound = false;
        $lFound = false;
        $mFound = false;

        $crawler->filter('.product-detail-configurator .product-detail-configurator-option-label')
            ->each(static function DCrawler $option) use ($blue$green$red$xl$l, &$blueFound, &$greenFound, &$redFound, &$xlFound, &$lFound, &$mFound): void {
                
'redirectParameters' => ['deepLinkCode' => 'example'],
            'loginError' => false,
            'waitTime' => 5,
        ]);

        $this->getContainer()->get('request_stack')->push($request);

        /** @var StorefrontResponse $response */
        $response = $controller->guestLoginPage($request$this->salesChannelContext);

        $contentReturn = $response->getContent();
        $crawler = new Crawler();
        $crawler->addHtmlContent((string) $contentReturn);

        $errorContent = $crawler->filterXPath('//div[@class="flashbags container"]//div[@class="alert-content"]')->text();

        static::assertStringContainsString($this->translator->trans('account.loginThrottled', ['%seconds%' => 5])$errorContent);
    }

    public function testAuthControllerLoginShowsRateLimit(): void
    {
        $loginRoute = $this->createMock(LoginRoute::class);
        $loginRoute->method('login')->willThrowException(CustomerException::customerAuthThrottledException(5));

        

        $finder = new Finder();

        $phpCoveragePerArea = [];
        $jsCoveragePerArea = [];

        foreach ($finder->in($this->projectDir . '/coverage/php')->depth(0)->directories() as $dir) {
            // We need to create a new Instance of Finder every time, because Symfony Finder doesn't reset it's internal state             $finder = new Finder();
            $xmlFiles = $finder->in($dir->getRealPath())->files()->name('cobertura.xml')->getIterator();
            $xmlFiles->rewind();
            $xml = new Crawler(file_get_contents($xmlFiles->current()->getRealPath()) ?: '');
            $phpCoveragePerArea[$dir->getFilename()] = $xml;
        }

        $finder = new Finder();
        $jsAreas = $finder->in($this->projectDir . '/coverage/js')->depth(0)->directories();

        foreach ($finder->in($this->projectDir . '/coverage/js')->depth(0)->directories() as $moduleDirectory) {
            $finder = new Finder();
            foreach ($finder->in($moduleDirectory->getRealPath())->depth(0)->directories() as $areaDirectory) {
                $finder = new Finder();
                $xmlFiles = $finder->in($areaDirectory->getRealPath())->files()->name('cobertura-coverage.xml')->getIterator();
                
$response = $browser->getResponse();
        static::assertSame(Response::HTTP_OK, $response->getStatusCode());

        $browser->request(
            'GET',
            '/checkout/offcanvas'
        );
        $response = $browser->getResponse();
        $contentReturn = $response->getContent();
        static::assertNotFalse($contentReturn);

        $crawler = new Crawler();
        $crawler->addHtmlContent($contentReturn);
        $errorContent = $crawler->filterXPath('//div[@class="alert-content"]')->text();
        foreach ($errorKeys as $errorKey) {
            static::assertStringContainsString($errorKey$errorContent);
        }
    }

    /** * @dataProvider errorDataProvider * * @param array<string> $errorKeys */
Home | Imprint | This part of the site doesn't use cookies.