To include the Selenium test as part of a build, the source code must
be in version control.
The build summary includes a snapshot of the test results. There is
also a Tests results page that highlights the build-on-build changes,
including errors, stack traces, and the ability to easily create a bug
that contains this information.
Selenium tests use graphical interface, so I do not think that they could be used on build stage, because application is not deployed yet. Am I right?
When they are talking about source code in the information snippet, its about the selenium code which is designed for testing the Web Application. You need to have it in version control.
Assuming that most of the people have source code version controlled. Taking Github as a version control you would provide the GitHub URL of the repo to your CI tool such as Jenkins. it would request you to provide that URL.
Once URL is configured you can trigger the build once the dev deploys their build in AUT.
They can be used on staging because there will be a program that calls each UI test. Each test will then create a browser instance and run the code in that instance. When the test is finished the browser instance closes and the program which is running that test records the results, potentially including screen shows in the case of failure.
The individual code for tests that is run needs to be available to the infrastructure programs that are running the tests and is typically in source control.
"so I do not think that they could be used on build stage, because application is not deployed yet" -- this depends on your test automation setup. If you have your selenium tests in the same code base as the System Under Test (SUT), then you could start the server within the build so that the application is available at "localhost" and then test it. Or you could optionally use a docker container to run the local server (the SUT) (accomplishing starting the server), and then test the pre-deployed application. Those are the major solutions for testing a pre-deployed application. Another option is to put the Selenium Tests in the same build that deploys the application, but put the Selenium Tests in a build step after the deployment.