19 End-to-end testing

end-to-end testing

Scenario tests are written in Javascript in which you describe how your application should behave during a certain interaction in a certain state. A program consists of one or more it code blocks (you can think of these as the requirements of your application), which consists of commands and expected results. The command tells the Runner to let the application perform an operation (such as turning a page or clicking a button), and it is expected to tell the Runner to verify the application state after execution (such as the value of a field or the current URL). If an expectation is not met, the Runner will mark it as "failed" and move on to the next validation. The scheme can also have beforeEach and afterEach code blocks, which will be executed before (after) the it code block, regardless of whether the code block is successful or not.

example:

describe('Buzz Client', function() {
it('should filter results', function() {
input('user').enter('jacksparrow');
element(':button').click();
expect(repeater('ul li').count()).toEqual(10);
input('filterText').enter('Bees');
expect(repeater('ul li').count()).toEqual(1);
});
});

API:

  • pause()
    pauses test execution until you execute resume() on the command line (or hit the resume button in the Runner UI).
  • sleep(seconds)

Pauses the test for the specified event, in seconds.
* browser().navigateTo(url)

Load the url into the test framework.
* browser().navigateTo(url, fn)

Load the url returned by the function into the test framework. The url in the parameter is used to test the output. You can use this api when the url is dynamic (meaning you don't know what the url is when you write the test).

  • browser().reload()

Refresh the loaded page in the test framework.

  • browser().window().href()

Returns window.location.href in the test framework page.

  • browser().window().path()

Returns window.location.pathname in the test framework page.

  • browser().window().search()

Returns window.location.search in the test framework page.

  • browser().window().hash()

Returns window.location.hash in the test framework page.

  • browser().location().url()
    returns $location.url() in the test framework page

  • browser().location().path()
    returns $location.path() in the test framework page

  • browser().location().search()
    returns $location.search() in the test framework page

  • browser().location().hash()
    returns $location.hash() in the test framework page

  • expect(future).{matcher}

Verify that the current future object satisfies the current match. All APIs will return a future object, which will be assigned a value after it is not executed. Matching is defined with angular.scenario.matcher, which uses the value of the future object to verify compound expectations, such as: expect(browser().location().href()).toEqual('http://www.google.com').

  • expect(future).not().{matcher}
    verifies whether the current future object value does not satisfy the current match.

  • using(selector, label)
    inspects the next DSL element option.

  • binding(name)
    returns the first binding value matching the given name.

  • input(name).enter(value)
    Enter the specified value in the specified input box.

  • input(name).check() Checks
    or unchecks the checkbox with the specified name.

  • input(name).select(value)
    selects the radio button with the specified name.

  • input(name).val()
    returns the value of the input element with the specified name.

  • repeater(selector, label).count()
    returns the number of elements selected with the specified jquery selector. The label in the parameter is used to detect the output.

  • repeater(selector, label).row(index)
    returns a binding (array) of the specified index of the element selected with the specified jquery selector. The label in the parameter is used to detect the output.

  • repeater(selector, label).column(binding)
    returns the value (array) of the column of the element selected with the specified jquery selector. The label in the parameter is used to detect the output.

  • select(name).option(value)
    returns the option with the specified value in select with the specified name.

  • select(name).option(value1, value2…)

Returns options in select with the specified name that match any of the given values.

  • element(selector, label).count()
    returns the number of elements that match the specified jquery selector. The label in the parameter is used to detect the output.

  • element(selector, label).click()
    simulates the click event of the element specifying the jquery selector. The label in the parameter is used to detect the output.

  • element(selector, label).query(fn)
    executes the function fn(selectedElements, done), selectedElements is the element that conforms to the jquery selector, and done is the callback after the function is executed. The label in the parameter is used to detect the output.

  • element(selector, label).{method}()

A method that returns the element selected by the specified jquery selector. The method can be the following jquery method: val, text, html, height, innerHeight, outerHeight, width, innerWidth, outerWidth, position, scrollLeft, scrollTop, offset. The label in the parameter is used to detect the output.
* element(selector, label).{method}(value)

Execute the method of the element selected by the specified jquery selector. The method can be the following jquery method: val, text, html, height, innerHeight, outerHeight, width, innerWidth, outerWidth, position, scrollLeft, scrollTop, offset. The label in the parameter is used to detect the output.
* element(selector, label).{method}(key)

Returns the result of executing the method of executing the element selected by the specified jquery selector, passing the key as a parameter. Methods can be: attr, prop, css. The label in the parameter is used to detect the output.
* element(selector, label).{method}(key, value)

Returns the result of executing the method on the element selected by the specified jquery selector, passing key and value as parameters. Methods can be: attr, prop, css. The label in the parameter is used to detect the output.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324769560&siteId=291194637