2

Is there a way to bypass UI for those actions which need to be performed before and (or) after the test? Is it possible to send simple GET or POST requests to the same test session instead of writing the script in the test?

For example, I want to write a test which checks if the record can be deleted. To do that, first of all I need to create the record. It doesn't seem to be a good choice to do it through the UI since it is not part of the test itself.

2 Answers2

1

It really depends on the application under test. You probably don't want to go making SQL calls to your database to create these records, unless you really know what you're doing. Even then, it will make your test automation break when that record changes.

Perhaps your application under test provides an API which will allow you to create a target record. That would be ideal, allowing you to make an API request then all you have to do in the UI is navigate to where the "user" would delete it.

Breaks Software
  • 1,721
  • 1
  • 10
  • 15
0

You can do pretty much everything by executing some Javascript into the page. Here is an example send an HTTP request with a Javascript call:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://www.google.com")

driver.execute_script("""
  var r = new XMLHttpRequest();
  r.open('POST', '/search', 0);
  r.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  r.send('q=bill+material&output=xml&client=test&site=operations&access=p');
  return r.responseText;
  """)

While it may be tempting to setup a test this way, I wouldn't recommend it since it will create new dependencies to the UI, increase the complexity and therefore increase the cost of maintenance of the tests.

Florent B.
  • 41,537
  • 7
  • 86
  • 101