Skip to content

Added PrintOptions to Documentation #1986

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

Closed
wants to merge 16 commits into from

Conversation

shbenzer
Copy link
Contributor

@shbenzer shbenzer commented Oct 9, 2024

Added PrintOptions to the documentation

Description

added subsection on PrintOptions to Interaction section
added tests for each example

Motivation and Context

make documentation more comprehensive
Covers issue #1941

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

Copy link

netlify bot commented Oct 9, 2024

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit cf14e14

@qodo-merge-pro qodo-merge-pro bot added documentation Improvements or additions to documentation tests Review effort [1-5]: 3 labels Oct 9, 2024
Copy link
Contributor

qodo-merge-pro bot commented Oct 9, 2024

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Bug
In the setSeleniumVersion method, the logOutput variable is used instead of seleniumVersion

Documentation Error
The ShrinkToFit section incorrectly refers to getBackground() and setBackground() methods instead of getShrinkToFit() and setShrinkToFit()

Copy link
Contributor

qodo-merge-pro bot commented Oct 9, 2024

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible bug
Correct a parameter mismatch in a method call

Fix the typo in the setSeleniumVersion method where logOutput is used instead of
seleniumVersion.

website_and_docs/content/documentation/test_practices/design_strategies.en.md [216-219]

 public void setSeleniumVersion(String seleniumVersion) {
   WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
-  clearAndType(field, logOutput);
+  clearAndType(field, seleniumVersion);
 }
  • Apply this suggestion
Suggestion importance[1-10]: 9

Why: The suggestion correctly identifies and fixes a critical bug where the wrong variable logOutput is used instead of seleniumVersion. This correction is crucial for the method to function as intended.

9
Possible issue
Fix a syntax error in a method call

Remove the extra parenthesis in the setTitle method's findElement call.

website_and_docs/content/documentation/test_practices/design_strategies.en.md [67-70]

 public void setTitle(String title) {
-  WebElement field = driver.findElement(By.id("issue_title")));
+  WebElement field = driver.findElement(By.id("issue_title"));
   clearAndType(field, title);
 }
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: The suggestion addresses a syntax error by removing an extra parenthesis, which is essential for the code to compile and run correctly. This fix is important for ensuring the method's functionality.

8
Enhancement
Add assertions to verify the expected values of print options after setting them

Consider adding assertions to verify the expected values after setting the print
options. This will ensure that the options are correctly applied and maintained.

examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java [15-17]

 PrintOptions printOptions = new PrintOptions();
 printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);
 PrintOptions.Orientation current_orientation = printOptions.getOrientation();
+assertEquals(PrintOptions.Orientation.LANDSCAPE, current_orientation);
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: Adding assertions to verify the expected values after setting the print options enhances the test's robustness by ensuring the options are correctly applied. This is a valuable improvement for test accuracy and reliability.

8
Performance
Optimize element locator strategy to improve performance and maintainability

Replace the repeated driver.findElement() calls with a more efficient approach, such
as using the @FindBy annotation or creating a map of element locators.

website_and_docs/content/documentation/test_practices/design_strategies.en.md [187-214]

+@FindBy(id = "issue_form_repro-command")
+private WebElement howToReproduceField;
+
+@FindBy(id = "issue_form_logs")
+private WebElement logOutputField;
+
+@FindBy(id = "issue_form_operating-system")
+private WebElement operatingSystemField;
+
 public void setHowToReproduce(String howToReproduce) {
-  WebElement field = driver.findElement(By.id("issue_form_repro-command"));
-  clearAndType(field, howToReproduce);
+  clearAndType(howToReproduceField, howToReproduce);
 }
 
 public void setLogOutput(String logOutput) {
-  WebElement field = driver.findElement(By.id("issue_form_logs"));
-  clearAndType(field, logOutput);
+  clearAndType(logOutputField, logOutput);
 }
 
 public void setOperatingSystem(String operatingSystem) {
-  WebElement field = driver.findElement(By.id("issue_form_operating-system"));
-  clearAndType(field, operatingSystem);
+  clearAndType(operatingSystemField, operatingSystem);
 }
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: The suggestion to use @FindBy annotations instead of repeated driver.findElement() calls improves code maintainability and performance by reducing redundancy and enhancing readability. This is a valid and beneficial change.

7
Best practice
Use a setup method to initialize common objects and navigate to the website, reducing code duplication

Consider using a setup method to initialize common objects and navigate to the
website, reducing code duplication across test methods.

examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java [13-18]

+private PrintOptions printOptions;
+
+@BeforeEach
+public void setup() {
+    driver.get("https://www.selenium.dev/");
+    printOptions = new PrintOptions();
+}
+
 @Test
-public void TestOrientation() 
+public void testOrientation() 
 {
-    driver.get("https://www.selenium.dev/");
-    PrintOptions printOptions = new PrintOptions();
     printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);
     PrintOptions.Orientation current_orientation = printOptions.getOrientation();
+    assertEquals(PrintOptions.Orientation.LANDSCAPE, current_orientation);
 }
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: Implementing a setup method to initialize common objects and navigate to the website reduces code duplication and enhances test maintainability, making the tests cleaner and more efficient.

7
Use constants for commonly used values to improve code maintainability and readability

Consider using constants for commonly used values like page ranges, scales, and
margins to improve code maintainability and readability.

examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java [24-26]

+private static final String DEFAULT_PAGE_RANGE = "1-2";
+
 PrintOptions printOptions = new PrintOptions();
-printOptions.setPageRanges("1-2");
+printOptions.setPageRanges(DEFAULT_PAGE_RANGE);
 String[] current_range = printOptions.getPageRanges();
  • Apply this suggestion
Suggestion importance[1-10]: 6

Why: Using constants for commonly used values like page ranges improves code maintainability and readability by reducing magic numbers and making the code easier to update.

6
Maintainability
Consolidate similar test methods to reduce code duplication and improve test organization

Consider consolidating similar test methods, such as TestScale() and TestSize(),
which both set and get the scale value, to reduce code duplication and improve test
organization.

examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java [30-58]

 @Test
-public void TestSize() 
+public void testScaleAndSize() 
 {
     driver.get("https://www.selenium.dev/");
     PrintOptions printOptions = new PrintOptions();
-    printOptions.setScale(.50);
-    double current_scale = printOptions.getScale();
+    
+    // Test scale
+    printOptions.setScale(0.50);
+    assertEquals(0.50, printOptions.getScale(), 0.001);
+    
+    // Test size (if different from scale)
+    printOptions.setScale(0.75);
+    assertEquals(0.75, printOptions.getScale(), 0.001);
 }
 
-@Test
-public void TestScale() 
-{
-    driver.get("https://www.selenium.dev/");
-    PrintOptions printOptions = new PrintOptions();
-    printOptions.setScale(.50);
-    double current_scale = printOptions.getScale();
-}
-
  • Apply this suggestion
Suggestion importance[1-10]: 5

Why: Consolidating similar test methods can reduce code duplication and improve test organization, but the suggestion may oversimplify by combining tests that might have different purposes or setups.

5

💡 Need additional feedback ? start a PR chat

@shbenzer shbenzer closed this Oct 9, 2024
@shbenzer shbenzer deleted the printOptions branch October 12, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Review effort [1-5]: 3 tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant