Difference between revisions of "Creating your first ta project"

From Test Automation Wiki
Jump to: navigation, search
 
(21 intermediate revisions by 5 users not shown)
Line 7: Line 7:
 
The easiest way to do this is using [[Lapis_Lazuli]]'s build in <code>create</code> function. This will create all needed folders and files to get started. If you like, you could also do this manually.
 
The easiest way to do this is using [[Lapis_Lazuli]]'s build in <code>create</code> function. This will create all needed folders and files to get started. If you like, you could also do this manually.
  
# Open the console
+
# Create a folder where you want to group your projects
# Go to the folder where you want to create you project
+
#* For example: <code>C:/ruby/projects/</code>
#* E.G.: <code>cd C:/ruby/projects/</code>
+
# Open CMD
# Write <code>lapis_lazuli create <projectname></code>
+
# Navigate to the folder by typing <code>C:/ruby/projects/</code>
 +
# Write <code> lapis_lazuli create <projectname> </code>
 
#* Where <projectname> is the name of your project without `<>`
 
#* Where <projectname> is the name of your project without `<>`
  
[[File:Ll-creat-project.png|200px|thumb|left|Console result creating project]]
+
[[File:Ll-create-project.png|200px|thumb|left|Console result creating project]]
 
<br clear="all" />
 
<br clear="all" />
  
=== Test running the project ===
+
 
 +
== Running the project for the first time ==
  
 
The project created by Lazis Lazuli has some basic scripts. To confirm it's working properly, let's run it!
 
The project created by Lazis Lazuli has some basic scripts. To confirm it's working properly, let's run it!
  
Continue from where we left off in the console:
+
Continue from where we left off in the CMD:
 +
# First we are going to install another gem <code>gem install bundler</code>
 +
# After the installation is complete, go to the directory of your project <code>cd <projectname></code>
 +
# Then write <code>bundle install</code>, this will automatically download all the required gems that you need for this project.
 +
# Again, wait for the installation to be complete.
 +
# Finally, to execute the project, write <code>bundle exec cucumber</code>
 +
 
 +
You should see a browser pop-up after a few seconds that automatically clicks through some pages. Once it's finished you should see something like this in CMD:
 
<source>
 
<source>
> cd <projectname>
+
16 scenarios (4 failed, 2 pending, 10 passed)
> cucumber
+
49 steps (4 failed, 10 skipped, 2 pending, 33 passed)
 +
0m31.978s
 +
 
 
</source>
 
</source>
  
You should see a browser pop-up after a few seconds and click trough some pages. In the end the console should show something like:
+
== Open a project ==
<source>
+
 
1 scenario (1 passed)
+
There are many text editors (free and paid) you could use to open the files. We recommend that you use [https://code.visualstudio.com/ VS Code].
3 steps (3 passed)
+
 
0m10.054s
+
There are also other programs to support the complete view of a project, like [https://atom.io/ Atom] that will improve the usability by making it easy to navigate between files and make the code more readable. Feel free to have a [https://www.google.nl/search?q=ruby+editors search] and find your own favorite editor.
</source>
+
 
 +
<p>'''Next up is [[Exploring your first cucumber project]]'''</p>
 +
 
 +
== Extra information ==
  
=== Common issues on your first run ===
+
=== About Bundle gem ===
  
* [[cannot load such file -- (...) (LoadError)]]
+
The purpose of using the Bundle gem is to make life easier. Bundle will help us to automatically install all required gems. And on top of that it's smart enough to know the dependencies between gems.  
** E.G. "cannot load such file -- watir-webdriver (LoadError)"
+
Basically Bundler will look in your <code>Gemfile</code> what is defined there and download all corresponding information. [http://bundler.io/man/gemfile.5.html More info about gemfiles].
* [[unable to obtain stable firefox connection]]
 
* [[Install ANSICON for coloured output]]
 
  
If other problems occured for you, please feel free to [[mailto:admin@testautomation.info|contact us]] so we can add the solution to our Wiki.
+
If a new version of Lapis Lazuli came out (see [https://rubygems.org/gems/lapis_lazuli/ Rubygems]), you can update your existing project by doing the following:
 +
# Delete <code>Gemfile.lock</code> from your project folder.
 +
# Open CMD, navigate to the project folder and write <code>bundle install</code>
 +
Done! Simply use <code>bundle exec cucumber</code> to run your project on the latest version.
  
== Folder structure ==
+
It is possible to run without Bundler by just writing <code>cucumber</code>. But this might result in unexpected errors that about missing Gems and/or because of using wrong Gem versions.
  
After creating your project, you will have a folder structure similar as below. Feel free to click around the folders and open the files. The recommended (free) program to use is [https://notepad-plus-plus.org/download/v6.9.2.html Notepad++].
+
=== Detailed information about every folder ===
  
 
<source>
 
<source>
Line 55: Line 70:
 
07. │ └─> validation_steps.rb
 
07. │ └─> validation_steps.rb
 
08. ├─┬/support/
 
08. ├─┬/support/
09. │ └─> env.rb
+
09. │ ├─> env.rb
10. ├─> example.feature
+
10. | └─> functions.rb
11. └─> mobile.feature
+
11. ├─> 1_basic.feature
12.──/log/
+
12. └─> 2_account.feature
13.──/results/
+
13. └─> 3_todo_list.feature
14.──/sceenshots/
+
14.──/log/
 +
15.──/results/
 +
16.──/sceenshots/
 
</source>
 
</source>
  
Line 67: Line 84:
 
* 04. /features/
 
* 04. /features/
 
** This is the core of your project. It contains the test cases, the code executed in the steps of your test cases and any other code you wish to write for your solution.
 
** This is the core of your project. It contains the test cases, the code executed in the steps of your test cases and any other code you wish to write for your solution.
* 10. example.feature
+
* 05. step_definitions
 +
** This folder contains the definitions of the steps you've described in your feature files. Any file ending with "_steps.rb" will be included in the execution. So you can create the files however you feel it will be most organized.
 +
* 11. 1_basic.feature
 
** This file contains your test cases, split up in Features which contain Scenario's which Contains Steps.
 
** This file contains your test cases, split up in Features which contain Scenario's which Contains Steps.
 
** More information about writing Feature files can be found in [[Writing_gherkin_test_cases_in_cucumber]]
 
** More information about writing Feature files can be found in [[Writing_gherkin_test_cases_in_cucumber]]
* 05. step_definitions
+
* 08. /support/
** This folder contains the definitions of the steps you've described in your feature files. Any file ending with "_steps.rb" will be included in the execution. So you can create the files however you feel it will be most organized.
+
** This folder contains files that supports writing steps or the execution.  
* 08. Support
+
** Env.rb does things like setting up a profile before a browser is opened.  
** More information about this in the Advanced tutorial.
+
** Functions.rb can be used to place methods you're using often.
* 12. log
+
* 14. /log/
 
** This will contain logging information after each test you have executed
 
** This will contain logging information after each test you have executed
* 13. results
+
* 15. /results/
 
** Can be used to export results of you test run to
 
** Can be used to export results of you test run to
* 14. screenshots
+
* 16. /screenshots/
 
** Any screenshot taken by your scripts will be stored in this folder.
 
** Any screenshot taken by your scripts will be stored in this folder.
 +
 +
=== Information about setting up your text editor ===
 +
 +
If you choose not to use a simple text editor like "Notepad", you sometimes need to setup the software to recognize the programming language we're using in this tutorial.
 +
Inside the text editor we need to download various plugins (also called add-ons or something similar) if they're not ready installed.
 +
In this tutorial we make use of "Ruby", "Cucumber", "Selenium" and "Gherkin".
 +
When these plugins are installed the text editor recognizes the code and if you make by mistake a typo the editor shows it. Some editors also help you write code by showing you the options you can choose from and extra information about the functions or methods you're using.
  
  
 
[[Category:Web Test Automation Tutorial|2]]
 
[[Category:Web Test Automation Tutorial|2]]

Latest revision as of 15:06, 18 January 2019

Creating the project folder

The easiest way to do this is using Lapis_Lazuli's build in create function. This will create all needed folders and files to get started. If you like, you could also do this manually.

  1. Create a folder where you want to group your projects
    • For example: C:/ruby/projects/
  2. Open CMD
  3. Navigate to the folder by typing C:/ruby/projects/
  4. Write lapis_lazuli create <projectname>
    • Where <projectname> is the name of your project without `<>`
Console result creating project



Running the project for the first time

The project created by Lazis Lazuli has some basic scripts. To confirm it's working properly, let's run it!

Continue from where we left off in the CMD:

  1. First we are going to install another gem gem install bundler
  2. After the installation is complete, go to the directory of your project cd <projectname>
  3. Then write bundle install, this will automatically download all the required gems that you need for this project.
  4. Again, wait for the installation to be complete.
  5. Finally, to execute the project, write bundle exec cucumber

You should see a browser pop-up after a few seconds that automatically clicks through some pages. Once it's finished you should see something like this in CMD:

16 scenarios (4 failed, 2 pending, 10 passed)
49 steps (4 failed, 10 skipped, 2 pending, 33 passed)
0m31.978s

Open a project

There are many text editors (free and paid) you could use to open the files. We recommend that you use VS Code.

There are also other programs to support the complete view of a project, like Atom that will improve the usability by making it easy to navigate between files and make the code more readable. Feel free to have a search and find your own favorite editor.

Next up is Exploring your first cucumber project

Extra information

About Bundle gem

The purpose of using the Bundle gem is to make life easier. Bundle will help us to automatically install all required gems. And on top of that it's smart enough to know the dependencies between gems. Basically Bundler will look in your Gemfile what is defined there and download all corresponding information. More info about gemfiles.

If a new version of Lapis Lazuli came out (see Rubygems), you can update your existing project by doing the following:

  1. Delete Gemfile.lock from your project folder.
  2. Open CMD, navigate to the project folder and write bundle install

Done! Simply use bundle exec cucumber to run your project on the latest version.

It is possible to run without Bundler by just writing cucumber. But this might result in unexpected errors that about missing Gems and/or because of using wrong Gem versions.

Detailed information about every folder

01.─┬/config/
02. ├─> config.yml
03. └─> cucumber.yml
04.─┬/features/
05. ├─┬/step_definitions/
06. │ ├─> interaction_steps.rb
07. │ └─> validation_steps.rb
08. ├─┬/support/
09. │ ├─> env.rb
10. | └─> functions.rb
11. ├─> 1_basic.feature
12. └─> 2_account.feature
13. └─> 3_todo_list.feature
14.──/log/
15.──/results/
16.──/sceenshots/
  • 01. /config/
    • This folder contains configuration information about your project. Some handy things you can do here is write credentials that will later be re-used throughout your whole automation project.
  • 04. /features/
    • This is the core of your project. It contains the test cases, the code executed in the steps of your test cases and any other code you wish to write for your solution.
  • 05. step_definitions
    • This folder contains the definitions of the steps you've described in your feature files. Any file ending with "_steps.rb" will be included in the execution. So you can create the files however you feel it will be most organized.
  • 11. 1_basic.feature
    • This file contains your test cases, split up in Features which contain Scenario's which Contains Steps.
    • More information about writing Feature files can be found in Writing_gherkin_test_cases_in_cucumber
  • 08. /support/
    • This folder contains files that supports writing steps or the execution.
    • Env.rb does things like setting up a profile before a browser is opened.
    • Functions.rb can be used to place methods you're using often.
  • 14. /log/
    • This will contain logging information after each test you have executed
  • 15. /results/
    • Can be used to export results of you test run to
  • 16. /screenshots/
    • Any screenshot taken by your scripts will be stored in this folder.

Information about setting up your text editor

If you choose not to use a simple text editor like "Notepad", you sometimes need to setup the software to recognize the programming language we're using in this tutorial. Inside the text editor we need to download various plugins (also called add-ons or something similar) if they're not ready installed. In this tutorial we make use of "Ruby", "Cucumber", "Selenium" and "Gherkin". When these plugins are installed the text editor recognizes the code and if you make by mistake a typo the editor shows it. Some editors also help you write code by showing you the options you can choose from and extra information about the functions or methods you're using.