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

Capture Page Screenshot should not overwrite if file already exist #502

Closed
aaltat opened this issue Sep 1, 2015 · 21 comments
Closed

Capture Page Screenshot should not overwrite if file already exist #502

aaltat opened this issue Sep 1, 2015 · 21 comments

Comments

@aaltat
Copy link
Contributor

aaltat commented Sep 1, 2015

The #501 tries to fix the issue that if the file already exist, then index is added to the file name and file is created with index in file name. Example:

| Capture Page Screenshot | filename.png |
| Capture Page Screenshot | filename.png |
| File Should Exist | filename.png |
| File Should Exist | filename-1.png |

Making issue also, because it helps perform better tracking and if I screw the pull request again, we do not lose the conversation history.

@pekkaklarck
Copy link
Member

Should this possibly be configurable with an optional parameter to avoid backwards incompatibility issues? Or should we support something like file-%d.png that tells S2L to replace ℅d with an index? It would also allow configuring where the index is added.

Regardless is the index configurable, it would be a good idea for the keyword to return an absolute path to the created image.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 1, 2015

There is overwrite=False parameter to control indexing and therefore the change is not backwards compatible. If we should set it to overwrite=True then it would work like the old implementation. This was briefly discussed in #426 but I also feel that we did not think the issue close enough.

I agree that returning the path is a good idea and I will make the change.

The %d is and interesting proposal. It also opens door to other formatting rules which could be nice to have (but perhaps in next commit and not in this one). With fast thinking, it should not be too hard to do.

So should this be default:

| Capture Page Screenshot | filename.png | 
| Capture Page Screenshot | filename.png |
| File Should Exist | filename.png |
| File Should Not Exist | filename-1.png |

In case of %d, should we support something like this

| Capture Page Screenshot | filename-%d.png | 
| Capture Page Screenshot | filename-%d.png |
| File Should Exist | filename-1.png |
| File Should Exist | filename-2.png |

In this scenario, should we also keep the overwrite argument.

@pekkaklarck
Copy link
Member

I don't think both ℅d and overwrite would be needed. Nor do I know which would be better solution...

@aaltat
Copy link
Contributor Author

aaltat commented Sep 2, 2015

My need is purely to avoid overwrites when I run my test with pabot. I simply want do define the filename with variable l, like ${BROWSER} and I would like avoid adding unique runing number in the end in the robot data.

The %d opens nice possibilities and could be more useful. Perhaps I should write a prototype and we can see in which way is the best.

@pekkaklarck
Copy link
Member

+1 for prototypes. After thinking this a bit more, I start to like %d approach more and more. Making overwrite the default behavior would be more convenient in some cases but being backwards incompatible in others is a big minus.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 3, 2015

I am also starting to think that %d is best way to go. Also returning the absolute path is a good idea. I will write prototype and let's see how it does look.

@aaltat aaltat changed the title Capture Page Screenshot should overwrite if file already exist Capture Page Screenshot should not overwrite if file already exist Sep 3, 2015
@aaltat
Copy link
Contributor Author

aaltat commented Sep 3, 2015

Made the proposal to support %d in #504

#504 proposal does not check does the file exist, but it also meets my needs. Personally I think the #504 is better and provides easier way extend the functionality in the future if needed. The only, although small, possibility for backwards incompatible is that someone might be already use %d in their filename.

@zephraph
Copy link
Member

zephraph commented Sep 4, 2015

I like this much, much better. I completely agree with both of you, the %d approach looks excellent.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 4, 2015

I am thinking the same way and let's go with the %d option. I will test few corner cases, read the code again and at least write better tests.

One thing which comes in my mind, that the code is written now in way that it does not count the number of %d in the filename. If there are more than one, it will raise an exception. But I will give it some thoughts and let's see...

@zephraph
Copy link
Member

zephraph commented Sep 4, 2015

I don't think it would make sense to allow more than one. Check for multiples, raise an exception, and document it.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 4, 2015

True, I will document it and write a test.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 4, 2015

I did updated documentation and re-write the tests in pull request #504. Review would be really nice.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 6, 2015

Did refactor the %d to {index} in #504 because it was causing more problems that it tried to solve. Also now it uses str.format in the underlying code and it solves the problems that the %d did have.

I am not totally sure, did I get the documentation totally in the way that would be correct, staring from here: https://github.com/robotframework/Selenium2Library/pull/504/files#diff-5346a546c6b37e3c016ad51e7155887dR55

Comments...

@zephraph
Copy link
Member

zephraph commented Sep 8, 2015

The content of the documentation itself looks good. Formatting can always be tricky, but nothing jumps out at me. You should probably generate out the documentation from your branch and make sure it looks right before merging.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 15, 2015

Closed because #504 was merged.

@aaltat aaltat closed this as completed Sep 15, 2015
@boakley
Copy link
Contributor

boakley commented May 26, 2017

I realize this is an old issue, but I think it might need to be revisited. There is a very bad default behavior which I think would be good to fix.

If I run a test, get some failures, then run robot again with --rerunfailed, the screenshots in my log become completely unreliable. While any re-ran tests will have good screenshots, all of the screenshots of the passing tests may be overwritten. It would be nice if the default behavior didn't cause this problem.

Here's a concrete example. Save this to /tmp/example.robot:

*** Settings ***
Library    Selenium2Library

Suite Setup     Open browser  http://example.com    chrome
Suite Teardown  close all browsers

*** Test Cases ***
Passing test
    go to   http://www.google.com
    capture page screenshot

Randomly failing test
    go to  http://www.bing.com
    capture page screenshot
    fail  bummer.

Run the following commands:

$ pybot /tmp/example.robot
$ pybot --output rerun.xml --rerunfailed output.xml /tmp/junk.robot
$ rebot --merge output.xml rerun.xml

When you do that, the screenshot in the first test will be of bing.com even though the test went to google.com and took a screenshot.

While this can be worked around by writing my own "capture page screenshot" keyword, it would be nice if the default behavior played nice with robot's -rerunfailed option out of the box.

@aaltat
Copy link
Contributor Author

aaltat commented May 26, 2017

And there are other ways to run into same problem, example with pabot. Reopened because it is valid issue.

Would you like to submit PR to fix the problem?

@aaltat aaltat reopened this May 26, 2017
@boakley
Copy link
Contributor

boakley commented May 26, 2017 via email

@aaltat
Copy link
Contributor Author

aaltat commented May 26, 2017

Does computed mean that the filename argument is with the default value or does it mean that filename can be given but contain the running index number? If it would be possible, I would prefer the later.

@boakley
Copy link
Contributor

boakley commented May 26, 2017 via email

@aaltat
Copy link
Contributor Author

aaltat commented May 26, 2017

Sounds good to me, specially with the {index.*} formatting.

boakley pushed a commit to boakley/Selenium2Library that referenced this issue May 31, 2017
…rwriting files

When computing a number to add to a screenshot filename, it will use a
number that doesn't cause an existing file to be overwritten.
@aaltat aaltat added this to the v2.0 milestone Jun 1, 2017
boakley pushed a commit to boakley/Selenium2Library that referenced this issue Jun 14, 2017
also removed some tags from tests to be consistent with other tests.
@aaltat aaltat closed this as completed in 31020a6 Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants