Luciana Fazan
Dúvida: Jenkins com PhpUnit e Selenium
07 de December de 2016 às 05:32AM
Olá,

Atualmente estou tentando rodar os testes gravados com Selenium dentro Jenkins.Para testes, utilizo um projeto disponível no git, que já consta configurado para conseguir rodar com jenkins: https://github.com/adambro/php-jenkins-example , funciona perfeitamente, porém, dentro da pasta do projeto, joguei um teste que gravei com selenium, fiz todas as configurações, como adicionar os plugins necessários e setar dentro das configurações do jenkins o local onde está o servidor Selenium RC. Enfim, ao construir a build pelo jenkins, via console recebo informação:


php-jenkins-example > clean:

[delete] Deleting directory C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\api
[delete] Deleting directory C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\coverage
[delete] Deleting directory C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\logs
[delete] Deleting directory C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\pdepend
[delete] Deleting directory C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\phpdox

php-jenkins-example > prepare:

[mkdir] Created dir: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\api
[mkdir] Created dir: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\coverage
[mkdir] Created dir: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\logs
[mkdir] Created dir: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\pdepend
[mkdir] Created dir: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\phpdox

php-jenkins-example > lint:


php-jenkins-example > phploc-ci:


php-jenkins-example > pdepend:


php-jenkins-example > phpmd-ci:


php-jenkins-example > phpcs-ci:

O sistema nÆo pode encontrar o caminho especificado.

php-jenkins-example > phpcpd-ci:


php-jenkins-example > static-analysis:


php-jenkins-example > phpunit-ci:


php-jenkins-example > phpdox:


php-jenkins-example > -check-failure:


BUILD FAILED
C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build.xml:247:7: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build.xml:252:57: PHPUnit did not finish successfully

Total time: 57.7533 seconds

Build step 'Invoke Phing targets' marked build as failure
Recording plot data
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Saving plot series data from: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\README.md
Not creating point with null values: y=null label= url=
Publishing Clover coverage report...
Clover xml file does not exist in: C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example called: build/logs/clover.xml and will not be copied to: C:\Program Files (x86)\Jenkins\jobs\php-jenkins-example\builds\7\cloverphp\clover.xml
Could not find 'build/coverage/build/logs/clover.xml'. Did you generate the XML report for Clover?
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at BUILD level C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example\build\api to C:\Program Files (x86)\Jenkins\jobs\php-jenkins-example\builds\7\htmlreports\API_Documentation
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing PHPUnit-3.x (default)
[xUnit] [INFO] - [PHPUnit-3.x (default)] - No test report file(s) were found with the pattern 'build/logs/junit.xml' relative to 'C:\Program Files (x86)\Jenkins\workspace\php-jenkins-example' for the testing framework 'PHPUnit-3.x (default)'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'PHPUnit-3.x (default)'?
[xUnit] [ERROR] - No test reports found for the metric 'PHPUnit' with the resolved pattern 'build/logs/junit.xml'. Configuration error?.
[xUnit] [INFO] - Failing BUILD.
[xUnit] [INFO] - There are errors when processing test results.
[xUnit] [INFO] - Skipping tests recording.
[xUnit] [INFO] - Stop build.
[JDepend] JDepend plugin is ready
[JDepend] Found 3 classes in 1 packages
Finished: FAILURE

O corpo do teste que gravei com selenium é:


<?php

class ManterUsuarioTest extends PHPUnit_Extensions_Selenium2TestCase {

protected function setUp() {
$this->setBrowser('chrome');
$this->setBrowserUrl('http://www1.mastercase.net/');
}

/**
* @test
*/
public function cadastrarUsuario() {

$this->url("/sandbox/gestor_inscricao/web/index.php");
$this->byXPath("//div[1]/div/div/div[3]/div/div/a")->click();
$this->byId("nomecompleto")->value("Ana Clara Barvosa");
$this->byId("email")->value("testetesteeee@teste5testeste.com.br");
$this->byId("senha")->value("851703");
$this->byId("resenha")->value("851703");
$this->byId("datanascimento")->value("17/03/1985");
$this->byId("select2-tipodocumento-container")->click();
$this->byId("documento")->value("01417777");
$this->byId("select2-tipocontato-container")->click();
$this->byId("telefone")->value("017477777");
$this->byXPath("//button[@type='button']")->click();
$this->byId("select2-id_pais-container")->click();
$this->byCssSelector("input.select2-search__field")->value("Brasil");
$this->byCssSelector("#select2-id_pais-results li")->click();
$this->byId("enderecoCep")->value("79106-087");
$this->byId("enderecoLogradouro")->value("Carlos Arruda");
$this->byId("enderecoEstado")->value("MS");
$this->byId("enderecoCidade")->value("C.G");
$this->byId("enderecoComplemento")->value("TSTE");
$this->byId("select2-tipoendereco-container")->click();
$this->byXPath("(//button[@type='button'])[4]")->click();
$this->byId("select2-tipocliente-container")->click();
$this->byCssSelector("input.select2-search__field")->value("Acadêmico");
$this->byCssSelector('#select2-tipocliente-results li')->click();
$this->byId("select2-id_universidade-container")->click();
$this->byCssSelector("input.select2-search__field")->value("Outra");
$this->byCssSelector('#select2-id_universidade-results li');
$this->byId("select2-id_especializacao-container")->click();
$this->byCssSelector("input.select2-search__field")->value("TÉCNICO");
//ao selecionar
$this->byCssSelector('#select2-id_especializacao-results li');
$this->byId("ano")->value("2014");
$this->byXPath("(//button[@type='button'])[6]")->click();
//$this->byLinkText("OK")->click();
}
/**
* @test
*/
public function efetuarLogin() {

$this->url("/sandbox/gestor_inscricao/web/");
// ERROR: Caught exception [TypeError: value.replace is not a function]
$this->byId("siteuser-email")->value("luciana@mastercase.com.br");
$this->byId("siteuser-senha")->value("851703");
$this->byId('siteuser-id_evento')->value('Testes do sistema Gestor de Eventos');
$this->byXPath("//button[@type='submit']")->click();
//usuario logou e fez logoff, clicou no botao sair
$this->byXPath("//div[1]/div/div/div/div/div[2]/a[4]");
}

/**
* @test
*/
public function recuperarSenhaEmailValido() {
$this->url("/sandbox/gestor_inscricao/web/");
$this->byXPath('//div[1]/div/div/div[2]/div/div/form/div[3]/a')->click();
$this->byId("email")->click();
$this->byId("email")->value("luciana@mastercase.com.br");
$this->byXPath("//button[@type='submit']")->click();
//clicou na mensagem de sucesso
$this->byXPath("//div[1]/div/div/div[2]/div/div/div")->click();
}

/**
* @test
*/
public function editarPerfil() {
$this->url("/sandbox/gestor_inscricao/web/");
$this->byId("siteuser-email")->value("ricardo@mastercase.com.br");
$this->byId("siteuser-senha")->value("!12teste");
$this->byXPath("//div[1]/div/div/div[2]/div/div/form/select")->click();
$this->byXPath("//div[1]/div/div/div[2]/div/div/form/select/option[4]")->click();
// ERROR: Caught exception [TypeError: value.replace is not a function]
$this->byXPath("//button[@type='submit']")->click();
$this->byXPath("//div[1]/div/div/div/div/div[2]/a[1]")->click();
sleep(5);
$this->byXPath("//div[2]/div/div[2]/ul/li[2]/a")->click();
sleep(5);
$this->byXPath("//div[2]/div[1]/div[3]/div/div[2]/div[2]/table/tbody/tr[2]/td[3]/button[1]")->click();
sleep(5);
$this->byXPath("//div[2]/div[2]/div/div/div[2]/form/div[3]/button")->click();
}
}
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.