-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from Cognifide/bugfix/resolution-and-subimage…
…-issues Bugfix/resolution and subimage issues
- Loading branch information
Showing
12 changed files
with
312 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...rc/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* AET | ||
* <p> | ||
* Copyright (C) 2013 Cognifide Limited | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.cognifide.aet.job.common.collectors.screen; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.openqa.selenium.Dimension; | ||
import org.openqa.selenium.Point; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ScreenCollectorImageTest { | ||
|
||
private static final Color black = new Color(0); | ||
|
||
@InjectMocks | ||
private ScreenCollector screenCollector; | ||
|
||
private BufferedImage testImage; | ||
|
||
|
||
@Before | ||
public void setup() throws Exception { | ||
String path = getClass().getResource("/screens/48x48.png").getFile(); | ||
File image = new File(path); | ||
testImage = ImageIO.read(image); | ||
} | ||
|
||
@Test | ||
public void testSubImageSize() { | ||
Point point = new org.openqa.selenium.Point(12, 12); | ||
Dimension dimension = new Dimension(24, 24); | ||
|
||
BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); | ||
|
||
assertThat(subImage.getHeight()).isEqualTo(24); | ||
assertThat(subImage.getWidth()).isEqualTo(24); | ||
|
||
} | ||
|
||
@Test | ||
public void testSubImageContent() { | ||
Point point = new org.openqa.selenium.Point(12, 12); | ||
Dimension dimension = new Dimension(24, 24); | ||
|
||
BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); | ||
boolean onlyBlack = true; | ||
|
||
for (int i = 0; i < subImage.getHeight(); i++) { | ||
for (int j = 0; j < subImage.getWidth(); j++) { | ||
onlyBlack &= black.equals(new Color(subImage.getRGB(i, j))); | ||
} | ||
} | ||
assertThat(onlyBlack).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testSubImageSize_whenElementIsHidden() { | ||
Point point = new Point(0, 0); | ||
Dimension dimension = new Dimension(0, 0); | ||
|
||
BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); | ||
|
||
assertThat(subImage.getHeight()).isEqualTo(1); | ||
assertThat(subImage.getWidth()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void testSubImageSize_whenElementIsBiggerThanImage() { | ||
Point point = new Point(20, 20); | ||
Dimension dimension = new Dimension(48, 48); | ||
|
||
BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); | ||
|
||
assertThat(subImage.getHeight()).isEqualTo(28); | ||
assertThat(subImage.getWidth()).isEqualTo(28); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%-- | ||
AET | ||
Copyright (C) 2013 Cognifide Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--%> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AET Demo Page</title> | ||
</head> | ||
<body style="display:none"> | ||
</body> | ||
</html> |
29 changes: 29 additions & 0 deletions
29
...n-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page_partial.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%-- | ||
AET | ||
Copyright (C) 2013 Cognifide Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--%> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AET Demo Page</title> | ||
</head> | ||
<body style="display:none"> | ||
<h1 class="someclass" style="display:none"></h1> | ||
</body> | ||
</html> |
28 changes: 28 additions & 0 deletions
28
integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%-- | ||
AET | ||
Copyright (C) 2013 Cognifide Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--%> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AET Demo Page</title> | ||
</head> | ||
<body style="height:1px"> | ||
</body> | ||
</html> |
29 changes: 29 additions & 0 deletions
29
...-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%-- | ||
AET | ||
Copyright (C) 2013 Cognifide Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--%> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AET Demo Page</title> | ||
</head> | ||
<body style="height:10px"> | ||
<div style="height:100px"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.