Let's suppose a Scrum team needs to implement a new feature.
Do QA engineers write automated tests for the feature at the same time as developers write code for the feature? In other words, QA engineers don't have anything to test yet, but are they already writing automated tests? So it's like the TDD practice (where we first create a test, and then write code), right?
Do QA-engineers write automated tests for the feature at the same time as developers write code of the feature?
Ideally yes. You need the two activities to be performed by a collaboration between developers and testers. TDD is another techniques that can be used. The idea is to move away from the behavior many are used to, which is for developers to write the code and then pass it of to testers, in stages.
If you cannot achieve the collaboration I mentioned above from the beginning, or test first, or use TDD, and you are still in a transition phase from the old approach, you should at least try to reduce as much as possible the time between writing the code and testing it and avoid the testing to pile up at the end of the sprint.
In the Scrum framework it is up to the team to decide how to deliver backlog items. Many teams do adopt a TDD / BDD style approach although this is usually accompanied by exploratory testing and UAT as well.
When it comes to managing TDD with continuous integration, the answer to your question is branching. Developers are normally expected to create a new branch for to-be incremented code and then a pull request for tested code (including the tests) for peer review. All depends on how your team works, so this is ultimately a question for your development team to work out.
The answer to this will depend upon the story and the definition of done for your organization. You could develop the test for a feature in one sprint and the feature in another. Likewise if your definition of done doesn’t include a test a test may or may not be added later.
I would recommend that you focus on what you want to get done, and use scrum to help you get that, than focus on what scrum allows or doesn’t.