Vote Votação 7 7
5 Minute Guide To Selenium IDE and Selenium Remote Control (Java) Test Tools 5 minuto Guia de selênio IDE e selênio controle remoto (Java) testar ferramentas
Angsuman Chakraborty Angsuman Chakraborty
July 1st, 2008 1 de julho de 2008 Selenium is a high quality open source test automation tool for web application testing . Selênio é uma alta qualidade de fonte aberta automação testar a ferramenta para testar aplicações web. Selenium runs in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh, Safari on the Mac, with plans to support Safari on iPhone soon. Selênio é executado no Internet Explorer, Mozilla Firefox e no Windows, Linux e Macintosh, o Safari no Mac, com planos de apoio à Safari iPhone em breve. Selenium test scripts are portable, can be run from browsers (using Selenium IDE) or from JUNit or NGUnit (using Selenium RC) etc.. Selênio teste scripts são portáteis, pode ser executado a partir de navegadores (usando Selênio IDE) ou a partir de JUnit ou NGUnit (usando Selênio RC) etc. For example, test scripts written using Selenium IDE in Firefox on Windows can run on Firefox in Mac or Linux, without changing any code. Por exemplo, teste escrito utilizando scripts Selênio IDE no Firefox no Windows pode correr em Linux ou Mac no Firefox, sem modificar nenhum código. Selenium tests run directly in browsers and so matches the end-user experience closely. Selênio testes executados diretamente nos navegadores e assim por correspondências a experiência do usuário final de perto.
There are three variants of Selenium, which can be used in isolation or in combination to create complete automation test suite for your web applications. Existem três variantes de Selênio, que pode ser usado isoladamente ou em combinação para criar completa automação teste para a sua suíte aplicações web.
Today we will discuss on how you can easily create automatic test scripts using Selenium IDE and convert them to JUnit tests (which uses Selenium Remote Control) which can be added to your JUnit based automatic regression test suite. Hoje vamos falar sobre como você pode facilmente criar teste automático utilizando scripts Selênio IDE e convertê-los a testes JUnit (que utiliza Selênio Remote Control) que podem ser adicionados à sua regressão teste automático baseado JUnit suite.
Creating a test plan in Selenium IDE is very easy, so we will use it to create few simple tests to begin with. Criando um teste no plano Selênio IDE é muito fácil, então vamos utilizá-lo para criar alguns testes simples para começar.
At this point you will see Selenium automatically recording your actions. Neste ponto você verá automaticamente Selênio gravação suas ações. Carefully note the commands, target and value. Nota cuidadosamente os comandos, alvo e valor. You can create and insert your own commands/ modify or even delete them. Você pode criar seus próprios comandos e inserir / modificar ou até mesmo eliminá-las. We will show some examples below. Vamos apresentar alguns exemplos abaixo. In the next section we will see how we can modify the generated tests to suit our needs. Na próxima secção iremos ver como podemos modificar os testes gerados para atender às nossas necessidades.
The default commands generated by Selenium when you are browsing the page as a normal user should be modified to make the test more robust and to add test cases to it. O padrão comandos gerados por Selênio quando você está navegando na página como um usuário normal deveria ser alterado de modo a tornar o teste mais robusto e de acrescentar os casos de teste para ele.
How to run above test plan (automatically generated java file from Selenium IDE) in command line? Como a correr acima plano de teste (gerado automaticamente java arquivo de Selênio IDE) na linha de comando?
The automatically generated java file SeleniumSTSanityTest.java is likely to have some defects. O arquivo gerado automaticamente java SeleniumSTSanityTest.java é susceptível de ter alguns defeitos. Fix it by comparing with the example below: Corrigi-lo, por comparação com o exemplo a seguir:
Let me know if you have any comments / suggestions on how we can improve this tutorial. Deixe-me saber se você tiver quaisquer comentários e sugestões sobre como podemos melhorar este tutorial.
There are three variants of Selenium, which can be used in isolation or in combination to create complete automation test suite for your web applications. Existem três variantes de Selênio, que pode ser usado isoladamente ou em combinação para criar completa automação teste para a sua suíte aplicações web.
- Selenium Core - In Selenium Core the tests scripts (written in HTML) and the Selenium Test Runner (written in Javascript) are uploaded to the same web server that hosts the application you are trying to test. Selênio Core - Em Selênio Core os testes scripts (escritos em HTML) e ao Selênio Test Runner (escrito em Javascript) são carregados para o mesmo servidor web que hospeda o aplicativo que você está tentando teste. It is a simpler form of Selenium, and suitable for non-developers, but it has some inherent limitations. Trata-se de uma forma mais simples de Selênio, e adequada para não-desenvolvedores, mas tem algumas limitações inerentes.
- Selenium IDE - Selenium IDE is a Firefox plugin, which includes the entire Selenium Core, allows you to record, play back, edit, and debug tests in browser. Selênio IDE - Selênio IDE é um plugin Firefox, o que inclui a totalidade do Selênio Core, permite gravar, reproduzir, editar e depurar testes no browser. It provides the simplest introduction to Selenium and is highly recommended for beginners. Ele fornece a mais simples introdução de Selênio e é altamente recomendado para iniciantes. You can save the tests / test suite created in xml or html format. Você pode salvar os ensaios / suíte teste criado em XML ou formato HTML. However to run them in an automated fashion you need Selenium Remote Control which is described next. No entanto a executá-los em uma forma automatizada você precisa de Selênio Controle Remoto que é descrito a seguir.
- Selenium Remote Control - The Selenium Remote Control allows you to develop test cases and test suites in Java (supports JUnit & NGUnit), PHP, Ruby, Python, Perl and even .NET. Selênio Remote Control - O Selénio Remote Control permite-lhe desenvolver casos de teste e testar suites em Java (suporta JUnit & NGUnit), PHP, Ruby, Python, Perl e até mesmo. NET. It is the most flexible setup but requires some development knowledge to set up and use. É o mais flexível configuração desenvolvimento, mas requer alguns conhecimentos para a criação e utilização.
- Selenium Grid - Selenium Grid allows several Selenium Remote Control servers to be accessed in parallel by Selenium Grid server. Selênio Grid - Grid Selênio Selênio Remote Control permite vários servidores para ser acessado em paralelo com Selênio Grid servidor. This is extremely useful for automated load and stress testing of web applications. Isto é extremamente útil para a carga e stress testes automatizados de aplicações web.
Today we will discuss on how you can easily create automatic test scripts using Selenium IDE and convert them to JUnit tests (which uses Selenium Remote Control) which can be added to your JUnit based automatic regression test suite. Hoje vamos falar sobre como você pode facilmente criar teste automático utilizando scripts Selênio IDE e convertê-los a testes JUnit (que utiliza Selênio Remote Control) que podem ser adicionados à sua regressão teste automático baseado JUnit suite.
How to create a test plan in Selenium IDE Como criar um plano de teste em Selênio IDE
Creating a test plan in Selenium IDE is very easy, so we will use it to create few simple tests to begin with. Criando um teste no plano Selênio IDE é muito fácil, então vamos utilizá-lo para criar alguns testes simples para começar.
- Install Instalar Selenium IDE 0.8.7 Selênio IDE 0.8.7 , a Firefox plugin. , Um plugin Firefox.
- After installing Selenium please restart your Firefox browser for the plugin to be activated. Após instalar Selênio por favor reinicie o navegador Firefox para o plugin para ser activado.
- Now you should see a new added menu item named Selenium IDE under your Firefox Tools menu. Agora deve ver um novo item do menu chamado acrescentou Selênio IDE sob seu Firefox menu Ferramentas.
- Open / browse the site for which you want to prepare a test case. Abrir / navegar no site para o qual pretende preparar um caso de teste.
- Start Selenium IDE from Firefox Tools->Selenium IDE . Iniciar a partir de Selênio IDE Firefox Ferramentas-> Selênio IDE.
- Browse some pages. Navegar algumas páginas.
- Now click red button to stop recording. Agora, clique em botão vermelho para parar a gravação.
At this point you will see Selenium automatically recording your actions. Neste ponto você verá automaticamente Selênio gravação suas ações. Carefully note the commands, target and value. Nota cuidadosamente os comandos, alvo e valor. You can create and insert your own commands/ modify or even delete them. Você pode criar seus próprios comandos e inserir / modificar ou até mesmo eliminá-las. We will show some examples below. Vamos apresentar alguns exemplos abaixo. In the next section we will see how we can modify the generated tests to suit our needs. Na próxima secção iremos ver como podemos modificar os testes gerados para atender às nossas necessidades.
How to create / modify / delete Selenium commands Como criar / modificar / excluir Selênio comandos
The default commands generated by Selenium when you are browsing the page as a normal user should be modified to make the test more robust and to add test cases to it. O padrão comandos gerados por Selênio quando você está navegando na página como um usuário normal deveria ser alterado de modo a tornar o teste mais robusto e de acrescentar os casos de teste para ele.
- Let's replace all click commands by clickAndWait . click simply clicks the specified link and goes on to execute the next command without waiting. Vamos substituir todos os comandos clique em clickAndWait. Clique simplesmente clicar no link indicado e passa a executar o próximo comando sem esperar. On the other hand clickAndWait waits for the new page to loaded before executing the next command. clickAndWait should be used to make more robust test cases. Por outro lado clickAndWait esperas para a nova página para carregados antes de executar o próximo comando. ClickAndWait devem ser usadas para tornar mais robusta casos de teste.
- Insert assertTextNotPresent command after each clickAndWait command to confirm a text must not be present in the browsed page. Inserir assertTextNotPresent comando depois de cada comando clickAndWait para confirmar um texto não deve estar presente na página navegados.
- Use assertTextPresent command to confirm a text must be present in the browsed page. Use assertTextPresent comando para confirmar um texto deve estar presente na página navegados.
- Finally to test your test plan please click green arrow button to play from the begining or to play from start point. Por último ensaio para testar seu plano de seta verde por favor clique no botão para jogar desde o início ou a desempenhar a partir de ponto de partida.
- Export the test plan as java file by Selenium IDE File->Export Test As->Java - Selenium RC (for example the file name is SeleniumSTSanityTest.java ) Exportar o plano de teste como arquivo em java Selênio IDE Arquivo-> Test Como Exportar-> Java - Selênio RC (por exemplo o nome do arquivo é SeleniumSTSanityTest.java)
- Then close your Firefox Selenium ID. Em seguida, feche o Firefox Selênio ID.
How to run above test plan (automatically generated java file from Selenium IDE) in command line? Como a correr acima plano de teste (gerado automaticamente java arquivo de Selênio IDE) na linha de comando?
- Download Baixar Selenium RC Selênio RC .
- Unzip it under the same directory where SeleniumSTSanityTest.java (exported test plan as java file from Selenium ID) was saved. Descompacte-lo sob o mesmo diretório onde SeleniumSTSanityTest.java (exportado teste java plano como arquivo de Selênio ID) foi salvo.
- Install junit. Instale JUnit.
- Go to directory where you unzip selenium-remote-control-1.0-beta-1-dist.zip file. Ir para o diretório onde você unzip-selênio de controle remoto-1.0-beta-1-dist.zip arquivo.
- Open a terminal and do the steps below- Abra um terminal e fazer as etapas a seguir -
- cd selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1 CD selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1
- java -jar selenium-server.jar (to run the server in interactive mode execute java -jar selenium-server.jar -interactive) java-jar-server.jar selênio (para executar o servidor em modo interativo executar java-jar selênio-server.jar-interactivo)
- If you get an error like Error: com.thoughtworks.selenium.SeleniumException: ERROR Server Exception: sessionId should not be null; has this session been started yet? then ensure that the browser is in the PATH before running the server. Se você obter um erro como Error: com.thoughtworks.selenium.SeleniumException: Erro de Servidor Exceção: sessionId não deve ser nulo; esta sessão tenha sido iniciado ainda? Então assegurar que o navegador está no caminho antes de executar o servidor. For example, you want to run the test in Firefox. Por exemplo, você deseja executar o teste no Firefox. Then you should do next two steps. Então você deve fazer duas próximas etapas.
- locate firefox-bin (for example it returns /usr/lib/firefox-1.5.0.12/firefox-bin) localizar firefox-bin (por exemplo, retorna / usr/lib/firefox-1.5.0.12/firefox-bin)
- export PATH=$PATH:/usr/lib/firefox-1.5.0.12/firefox-bin; exportação PATH = $ PATH: / usr/lib/firefox-1.5.0.12/firefox-bin;
Note: There is an alternative way to fix above error (browser is not in path). Nota: Não existe uma forma alternativa para corrigir erros acima (navegador não está no caminho). Simply replace chrome with browser PATH in SeleniumSTSanityTest.java file. Basta substituir crómio com navegador PATH SeleniumSTSanityTest.java no arquivo. For example: Por exemplo:
line
setUp("http://blog.taragana.com", "*chrome"); Configuração ( "http://blog.taragana.com", "* cromo");
becomes torna-se
setUp("http://blog.taragana.com", "*firefox /usr/lib/firefox-1.5.0.12/firefox-bin"); Configuração ( "http://blog.taragana.com", "* firefox / usr/lib/firefox-1.5.0.12/firefox-bin");
in SeleniumSTSanityTest.java . em SeleniumSTSanityTest.java.
To run the test in opera browser replace chrome with opera . Para executar o teste no navegador Opera substituir crómio com ópera.
Now the selenium server is running and you have to run the Java client located in selenium-remote-control-1.0-beta-1/selenium-java-client-driver-1.0-beta-1. Agora, o selênio servidor está funcionando e você terá que executar os clientes localizados em Java selenium-remote-control-1.0-beta-1/selenium-java-client-driver-1.0-beta-1. - Open another terminal. Abra outro terminal.
- export CLASSPATH=.:selenium-remote-control-1.0-beta-1/selenium-java-client-driver-1.0-beta-1/selenium-java-client-driver.jar:/usr/share/java/junit.jar exportação CLASSPATH =.: selenium-remote-control-1.0-beta-1/selenium-java-client-driver-1.0-beta-1/selenium-java-client-driver.jar: / usr / share / java / JUnit. jar
- javac SeleniumSTSanityTest.java javac SeleniumSTSanityTest.java
- java SeleniumSTSanityTest Java SeleniumSTSanityTest
The automatically generated java file SeleniumSTSanityTest.java is likely to have some defects. O arquivo gerado automaticamente java SeleniumSTSanityTest.java é susceptível de ter alguns defeitos. Fix it by comparing with the example below: Corrigi-lo, por comparação com o exemplo a seguir:
import com.thoughtworks.selenium.*;importação com.thoughtworks.selenium .*;
import junit.framework.*;importação junit.framework .*;
import java.util.regex.Pattern;java.util.regex.Pattern importação;
public class SeleniumSTSanityTest extends SeleneseTestCase { público classe SeleniumSTSanityTest estende SeleneseTestCase (
public void setUp() throws Exception { public void setup () throws Exceção (
setUp("http://blog.taragana.com", "*chrome"); // to run the test in opera replace chrome with opera Configuração ( "http://blog.taragana.com", "* cromo"); / / para executar o ensaio de ópera substituir crómio com ópera
} )
public void testSimpleThoughts() throws Exception { public void testSimpleThoughts () throws Exceção (
selenium.open(""); selenium.open ("");
assertFalse(selenium.isTextPresent("WordPress database error: [")); assertFalse (selenium.isTextPresent ( "WordPress database erro: ["));
assertTrue(selenium.isTextPresent("2003-2008")); assertTrue (selenium.isTextPresent ( "2003-2008"));
selenium.open("/index.php/category/programming/java"); selenium.open ( "/ index.php / categoria / programação / java");
selenium.waitForPageToLoad("30000"); selenium.waitForPageToLoad ( "30000");
assertFalse(selenium.isTextPresent("WordPress database error: [")); assertFalse (selenium.isTextPresent ( "WordPress database erro: ["));
assertTrue(selenium.isTextPresent("2003-2008")); assertTrue (selenium.isTextPresent ( "2003-2008"));
selenium.click("//img[@alt='Übersetzen Sie zum Deutsch/German']"); selenium.click ( "/ / img [@ alt =" Übersetzen Sie zum Deutsch / Alemão']");
selenium.waitForPageToLoad("30000"); selenium.waitForPageToLoad ( "30000");
assertFalse(selenium.isTextPresent("WordPress database error: [")); assertFalse (selenium.isTextPresent ( "WordPress database erro: ["));
assertTrue(selenium.isTextPresent("2003-")); assertTrue (selenium.isTextPresent ( "2003 -"));
selenium.click("//img[@alt='Přeložit do Čech/Czech']"); selenium.click ( "/ / img [@ alt =" Přeložit fazer Čech / checo']");
selenium.waitForPageToLoad("60000"); selenium.waitForPageToLoad ( "60000");
assertFalse(selenium.isTextPresent("WordPress database error: [")); assertFalse (selenium.isTextPresent ( "WordPress database erro: ["));
assertTrue(selenium.isTextPresent("2003")); assertTrue (selenium.isTextPresent ( "2003"));
} )
public static Test suite() { public static Test suite () (
return new TestSuite(SeleniumSTSanityTest.class); regressar novo TestSuite (SeleniumSTSanityTest.class);
} )
public static void main(String args[]) { public static void main (String args []) (
junit.textui.TestRunner.run(suite()); junit.textui.TestRunner.run (suite ());
} )
} )
Let me know if you have any comments / suggestions on how we can improve this tutorial. Deixe-me saber se você tiver quaisquer comentários e sugestões sobre como podemos melhorar este tutorial.
Filed under Arquivado em Headline News Headline News , De Java Software Java Software , De Pro Blogging Blogging Pro , De Web | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | este artigo |
Email this Article E-mail este artigo
You may also like to read Você pode também gosta de ler |



