Skip to content

Instantly share code, notes, and snippets.

@MaxMorais
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxMorais/7d8e8154abf576930331 to your computer and use it in GitHub Desktop.
Save MaxMorais/7d8e8154abf576930331 to your computer and use it in GitHub Desktop.
ERPNext setup with Salad

First how it works

ERPNext automated Setup

What is Salad

Salad, is test automation tool, designed on top of Lettuce, to do tests using files that contains the description of each task, these files are named features

Setuping your environment

The test environment aren't made in the server, because normal users aren't not in the server side, so, do you up your test environment in your local machine, with a graphic desktop environment with firefox, python, git, pip and virtualenv installed previously.

  • Create one virtualenv like salad in your development folder with the command virtualenv salad
  • Into the virtualenv folder, turn on the virtualenv with the command source bin/activate
  • fork the salad, from the github using git clone https://github.com/salad/salad salad-sources
  • In the salad-sources install the requirements with pip install python-levenshtein
  • Setup the package in development mode python setup.py develop
  • Done

Running you first feature

  • Create a new-site in bench using admin as password for the Administrator
  • Start the bench using this new-site
  • Clone this gist in your features folder git clone https://gist.github.com/MaxMorais/7d8e8154abf576930331 features

TIP: 00 is to manage the order the the salad will run the features, the feature 00, run first of 01

Running the test case

Goto the virtualenv folder and run salad

It will start a new browser, and run the steps.

Feature: Ensuring that the instance works, and the UI loads fine
In order to make sure that ERPNext works
As a First Login and Setup of an User
I open the Instance URL using salad
Scenario: First Login
Given I am logged in
When I look around
Then I should see "ERPNext" anywhere in the page
Scenario: Instance Setup - Step 1 [The Language]
Given I look around
When I select the option "english" in the field "language"
And I move to next
Then I should see "Region" somewhere in the page
Scenario: Instance Setup - Step 2 [The Location]
Given I look around
When I select the option "United States" in the field "country"
And I select the option "America/New_York" in the field "timezone"
And I select the option "USD" in the field "currency"
And I move to next
Then I should see "The First User: You" somewhere in the page
Scenario: Instance Setup - Step 3 [System Admin]
Given I look around
When I fill the field "first_name" with "Test"
And I fill the field "last_name" with "User"
And I fill the field "email" with "test_demo@our_company.com"
And I fill the field "password" with "test"
And I move to next
Then I should see "The Organization" somewhere in the page
Scenario: Instance Setup - Step 4 [The Organization]
Given I look around
When I fill the field "company_name" with "Wind Power LLC"
And I fill the field "company_tagline" with "Wind Mills for a Better Tomorrow"
And I fill the field "bank_account" with "Citibank"
And I select the option "Standard" in the field "chart_of_accounts"
And I fill the field "fy_start_date" with "01-01-2015"
And I fill the field "fy_end_date" with "12-31-2015"
And I move to next
Then I should see "The Brand" somewhere in the page
Scenario: Instance Setup - Step 5 [The Brand]
Given I look around
When I move to next
Then I should see "Add Users" somewhere in the page
Scenario: Instance Setup - Step 6 [The Users]
Given I look around
When I move to next
Then I should see "Add Taxes" somewhere in the page
Scenario: Instance Setup - Step 7 [The Taxes]
Given I look around
When I move to next
Then I should see "Your Customers" somewhere in the page
Scenario: Instance Setup - Setup 8 [The Customers]
Given I look around
When I fill the field "customer_1" with "Standard Customer"
And I move to next
Then I should see "Your Suppliers" somewhere in the page
Scenario: Instance Setup - Setup 9 [The Supplier]
Given I look around
When I fill the field "supplier_1" with "Standard Supplier"
And I move to next
The I should see "Your Products or Services" somewhere in the page
Scenario: Instance Setup - Setup 10 [The Products or Services]
Given I look around
When I fill the field "item_1" with "Standard Product"
And I complete the setup
Then should see "Test User" somewhere in the page
# -*- coding: utf-8 -*-
from lettuce import step, world
@step(r"go to the home page")
def go_to_home(step):
step.given('I visit the url "http://localhost:8000"')
@step(u"go the the desk")
def go_to_desk(step):
step.given('I visit the url "http://localhost:8000/desk"')
@step('select the option "([^"]*)" in the field "([^"]*)"')
def select_frappe_option(step, option, selector):
step.behave_as("""
Given I scroll to "{selector}"
And I click on the element with the xpath "{option}"
And I hit the ESCAPE key
""".format(selector="select[data-fieldname='{}']".format(selector),
option="//option[@value='{}']".format(option)))
@step(u'fill the field "([^"]*)" with "([^"]*)"')
def fill_frappe_form(step, selector, value):
step.behave_as("""
Given I scroll to "{selector}"
And I click on the field with the css selector "{selector}"
And I fill in the field with the css selector "{selector}" with "{value}"
""".format(selector="input[data-fieldname='{}']".format(selector), value=value))
@step('move to ([^"]*)')
def moving(step, move_to):
page = str(int(world.browser.url[-1],10)+1)
humanized = page + ('st' if page[-1] == '1' else 'nd' if page[-1] == '2' else 'rd' if page[-1] == '3' else 'th')
step.given('I click on the {} element with the css selector "a.next-btn.btn.btn-primary.btn-sm"'.format(humanized))
@step(r'I am logged in')
def is_logged_in(step):
step.behave_as(
"""
Given I go to the home page
And I click on the link with the text "Login"
And I wait 1 second
And I click on the field with the id "login_email"
And I fill in the field with id "login_email" with "{user}"
And I click on the field with the id "login_password"
And I fill in the field with id "login_password" with "{pwd}"
And I click the button with the css selector ".btn-login"
And I wait 2 seconds
""".format(user='Administrator', pwd='admin')
)
@step('I complete the setup')
def completing_setup(step):
step.behave_as("""Given I click on the last element with the css selector "a.complete-btn.btn.btn-primary.btn-sm"
And I wait 30 seconds""")
@step('scroll to "([^"]*)"')
def scroll_to(step, selector):
try:
world.browser.execute_script('frappe.ui.scroll("{}")'.format(selector));
except NotImplementedError:
logger.info("Attemped to run javascript in javascript-disabled browser. Movin along.")
@step('add a child on "([^"]*)"')
def add_child(step, table):
step.behave_as("""
Given I click on the element with the css selector "{selector}"
And I scrool to "{selector}"
""".format(selector="[data-fieldname='{}'] .grid-row-open .btn-success".format(table)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment