Make WebDriver::getLocator (and WebDriver::getStrictLocator) public

Abierto
#50 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
php
Área
testing-qa

Línea de trabajo

Comienza por los puntos de entrada WebDriver::getLocator y WebDriver::getStrictLocator e inspecciona cómo reciben argumentos WebDriverBy las funciones públicas como WebDriver::findElements. Verifica que el módulo obtenido mediante $this->getModule('WebDriver') pueda usar ambos servicios de localización desde una acción personalizada, y confirma que el manejo de selectores no válidos siga estando cubierto por el comportamiento existente mostrado en el issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

What are you trying to achieve?

Write a custom action that uses the WebDriver locator service to locate an element by its selector string.
I would like to do this by getting the web driver module with $this->getModule('WebDriver') rather than extending WebDriver to keep my testing architecture consistent with other modules I've written.

What do you get instead?

Unable to use the functions because they're protected.

    /**
     * @param $selector
     * @return WebDriverBy
     * @throws \InvalidArgumentException
     */
    protected function getLocator($selector)
    {
        if ($selector instanceof WebDriverBy) {
            return $selector;
        }
        if (is_array($selector)) {
            return $this->getStrictLocator($selector);
        }
        if (Locator::isID($selector)) {
            return WebDriverBy::id(substr($selector, 1));
        }
        if (Locator::isCSS($selector)) {
            return WebDriverBy::cssSelector($selector);
        }
        if (Locator::isXPath($selector)) {
            return WebDriverBy::xpath($selector);
        }
        throw new \InvalidArgumentException("Only CSS or XPath allowed");
    }

   // ...and

    /**
     * @param array $by
     * @return WebDriverBy
     */
    protected function getStrictLocator(array $by)
    {
        $type = key($by);
        $locator = $by[$type];
        switch ($type) {
            case 'id':
                return WebDriverBy::id($locator);
            case 'name':
                return WebDriverBy::name($locator);
            case 'css':
                return WebDriverBy::cssSelector($locator);
            case 'xpath':
                return WebDriverBy::xpath($locator);
            case 'link':
                return WebDriverBy::linkText($locator);
            case 'class':
                return WebDriverBy::className($locator);
            default:
                throw new MalformedLocatorException(
                    "$by => $locator",
                    "Strict locator can be either xpath, css, id, link, class, name: "
                );
        }
    }
Details

It seems to me that these are services that the WebDriver module should expose, as some public WebDriver functions take WebDriverBy arguments (e.g. WebDriver::findElements). We need some service to get these WebDriverBy arguments, or we won't be able to use the public function calls that are exposed through $this->getModule('WebDriver');. Alternatively, maybe the WebDriver module should expose some public findElement type of function that takes a selector string rather than a WebDriverBy instance.

  • Codeception version: 2.2.10
  • PHP Version: 7.0.10

Apologies if this has already been discussed, I didn't see it on the issues board. And thanks for making such a fantastic tool!

Lenguaje dominante
PHP
Estrellas
39
Forks
25
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Codeception/module-webdriver

Todos los issues de Codeception/module-webdriver

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.