Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add firefox html5 selenium test #14905

Closed

Conversation

BillAnastasiadis
Copy link
Contributor

@BillAnastasiadis BillAnastasiadis commented May 13, 2022

still WIP
This is a POC exploring ways to use python-selenium in openqa for specific tests. The test runs a python script which uses selenium to access https://html5test.opensuse.org/ and check a number of values and scores, which are then parsed in perl to determine success/failure of the test.

The test also uploads the geckodriver log and the full test result log.

(limits and checks are arbitrarily selected for the sake of demonstration)

@BillAnastasiadis
Copy link
Contributor Author

BillAnastasiadis commented May 17, 2022

@foursixnine the script is - for the time being - in data, exactly where the ticket said it shouldn't be :p

The question here is: ImageMagick also makes use of a (bash) script, which also resides in data. If you take this into account, it makes sense that possible future selenium scripts would reside in a dedicated folder in data too.

On the other hand, the scripts could also reside in the dedicated scripts repo of os-autoinst. No personal preference between the two. I'm open to suggestions.

assert_script_run "wget --quiet " . data_url('selenium/selenium_html5.py') . " -O selenium_html5.py";

# run selenium script, parse results and upload logs
assert_script_run "python3 selenium_html5.py >&1 | tee selenium_output.txt ", timeout => 120;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with this is that the assert_script_run will always pass, as it returns the exit code from the second part of the pipe. you could use script_output i guess. i havent found a better way to solve this myself. wdyt?

Copy link
Member

@foursixnine foursixnine May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make the script write the output to a file, so if something is off with the script, a failure is a failure. On top of that either pytest or TAP for python should be good enough (https://pypi.org/project/pytest-tap/)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that's why I write the first command output to the output.txt file and later read from that to make sure everything went fine. I do need to make the checks a bit more thorough though - thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can always set pipefail in bash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be made to work in various ways (pipefail and pipestatus don't seem to work correctly though, don't know if it's openqa related or what is the exact problem) but it is not needed, as there are stuff to be done after the selenium script runs anyway, so aborting on failure was not the intended action.

Comment on lines 41 to 44
foreach my $line (split(/\n/, $res)) {
if (index($line, 'FAIL') != -1) {
my ($match) = $line =~ /\[\[ ( (?:(?!\]\]).)* ) \]\]/x;
push(@errs, $match);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can look into pytest? another idea is to rather evaluate the exit code of the script, anything that is a failure, is more than 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here was that I did not want the script failing causing a test fail. I thought that as long as all scheduled tests and checks are conducted, it's not important if the script itself failed or not. This approach does have it's problems too, though - I don't even check for missing tests (due to the script failing early, for example). Let me make it better.

About pytest I wasn't so sure about the python3.7 requirement, but I can play with it and see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, I went with neither options, but rather checking the output file in the end. I could just let the python script fail and fail the test, but then the output file would not exist and be uploaded for the user to check details at their leisure. Pytest felt wrong for this purpose, see the related ticket for more details on that.

enter_cmd "exit";
assert_script_run("pip3 install selenium");
assert_script_run "mkdir temp_selenium && cd temp_selenium";
assert_script_run "wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz && tar -xf geckodriver-v0.30.0-linux64.tar.gz";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can be packaged or if it's packaged already (Not for us atm, more of a rethoric question)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcermak this is the package I was mentioning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that since the dirs and scripts used by different tests won't be the same (probably - unless we standardize the way selenium is used), the only "generic" part of this is installing selenium, which is a single command

}
send_key_until_needlematch('firefox-testvideo', 'spc', 30, 5);
$self->exit_firefox;
upload_logs('geckodriver.log', log_name => 'html5-geckodriver-log.txt');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the geckodriver-log have that could be of interest for us? any errors or things whre it should be parsed or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it would be useful to have in case of driver errors that lead to abortion of the test. But I don't see a reason to parse - if the test fails, the reviewer can take a look at the log and determine what exactly the problem is, if it's driver related

@stale
Copy link

stale bot commented Sep 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If it's still needed, you can add labels WIP or notready to it

@stale stale bot added the stale Stale pull request, are to be deleted within 90 days label Sep 9, 2022
@stale
Copy link

stale bot commented Sep 24, 2022

This Pull Request has been automatically closed as it didn't have any activity in the last 97 days. Thank you.

@stale stale bot closed this Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale pull request, are to be deleted within 90 days
Projects
None yet
4 participants