I need to upload an image to a term as well as to a node using BEHAT with Drupal API. How this can be possible?
You need to define a Behat step for it. A possible way would be to define a method to be executed before creating a node (labelled with
@beforeNodeCreate), to upload the file first and then to attach its
fid to the appropriate file field of the node or term.
A possible way of doing it (for Drupal 8) is explained in detail here: https://webscope.co.nz/testing-image-and-file-fields-with-behat