-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test single page export, and popup visibilities
- Loading branch information
Showing
9 changed files
with
171 additions
and
40 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
18 changes: 18 additions & 0 deletions
18
e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/MultipleLinksOptionsPage.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,18 @@ | ||
package org.yorkxin.copyasmarkdown.e2e; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
|
||
import java.util.List; | ||
|
||
// page_url = about:blank | ||
public class MultipleLinksOptionsPage { | ||
@FindBy(css = "input[type=checkbox][data-custom-format-context='multiple-links']") | ||
public List<WebElement> allCustomFormatCheckboxes; | ||
|
||
public MultipleLinksOptionsPage(WebDriver driver) { | ||
PageFactory.initElements(driver, this); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/SingleLinkOptionsPage.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,18 @@ | ||
package org.yorkxin.copyasmarkdown.e2e; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
|
||
import java.util.List; | ||
|
||
// page_url = about:blank | ||
public class SingleLinkOptionsPage { | ||
@FindBy(css = "input[type=checkbox][data-custom-format-context='single-link']") | ||
public List<WebElement> allCustomFormatCheckboxes; | ||
|
||
public SingleLinkOptionsPage(WebDriver driver) { | ||
PageFactory.initElements(driver, this); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/popup/CurrentTabTest.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,56 @@ | ||
package org.yorkxin.copyasmarkdown.e2e.popup; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
import org.yorkxin.copyasmarkdown.e2e.CustomFormatPage; | ||
import org.yorkxin.copyasmarkdown.e2e.DemoPageData; | ||
|
||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.UnsupportedFlavorException; | ||
import java.io.IOException; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class CurrentTabTest extends BaseTest { | ||
@Test | ||
public void currentTabLink() throws IOException, UnsupportedFlavorException, InterruptedException { | ||
// XXX: because the popup is using chrome.tabs.query() to get tab with id from parameter, | ||
// it is necessary to grant the 'tabs' permission. Technically, 'activeTab' is the tab that opens the popup window. | ||
// In the actual Chrome / Firefox, 'tabs' permission is not required to get title / url of the current tab. | ||
grantPermission("tabs"); | ||
|
||
DemoPageData dpd = openDemoTabs(false); | ||
openPopupWindow(dpd); | ||
popupPage.currentTabLinkButton.click(); | ||
Thread.sleep(500); | ||
String expected = "[Page 0 - Copy as Markdown](http://localhost:5566/0.html)"; | ||
assertEquals(expected, clipboard.getData(DataFlavor.stringFlavor)); | ||
} | ||
|
||
@Test | ||
public void currentTabAsCustomFormat() throws InterruptedException, IOException, UnsupportedFlavorException { | ||
openCustomFormatPage("single-link", "1"); | ||
CustomFormatPage cfp = new CustomFormatPage(driver); | ||
|
||
cfp.inputName.clear(); | ||
cfp.inputName.sendKeys("My Format A"); | ||
cfp.inputTemplate.sendKeys(""" | ||
'{{title}}','{{url}}' | ||
"""); | ||
cfp.checkboxShowInMenus.click(); | ||
cfp.saveButton.click(); | ||
|
||
DemoPageData dpd = openDemoTabs(false); | ||
openPopupWindow(dpd); | ||
assertTrue(popupPage.currentTabCustomFormat1.isDisplayed()); | ||
assertEquals(popupPage.currentTabCustomFormat1.getText(), "Current tab (My Format A)"); | ||
driver.switchTo().window(popupHandle); | ||
popupPage.currentTabCustomFormat1.click(); | ||
Thread.sleep(200); | ||
String expected = """ | ||
'Page 0 - Copy as Markdown','http://localhost:5566/0.html' | ||
"""; | ||
assertEquals(clipboard.getData(DataFlavor.stringFlavor), expected); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/popup/DisplayTest.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,60 @@ | ||
package org.yorkxin.copyasmarkdown.e2e.popup; | ||
|
||
import org.openqa.selenium.WebElement; | ||
import org.testng.Assert; | ||
import org.testng.annotations.*; | ||
import org.yorkxin.copyasmarkdown.e2e.DemoPageData; | ||
import org.yorkxin.copyasmarkdown.e2e.MultipleLinksOptionsPage; | ||
import org.yorkxin.copyasmarkdown.e2e.SingleLinkOptionsPage; | ||
|
||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.UnsupportedFlavorException; | ||
import java.io.IOException; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
public class DisplayTest extends BaseTest { | ||
@Test | ||
public void counter() { | ||
DemoPageData dpd = openDemoTabs(false); | ||
openPopupWindow(dpd); | ||
Assert.assertTrue(popupPage.counterAll.isDisplayed()); | ||
Assert.assertTrue(popupPage.counterHighlighted.isDisplayed()); | ||
Assert.assertEquals("8", popupPage.counterAll.getText()); | ||
Assert.assertEquals("3", popupPage.counterHighlighted.getText()); | ||
} | ||
|
||
@Test | ||
public void showCustomFormatOfExportTabs() { | ||
openMultipleLinksOptionsPage(); | ||
MultipleLinksOptionsPage page = new MultipleLinksOptionsPage(driver); | ||
for (WebElement checkbox : page.allCustomFormatCheckboxes) { | ||
if (!checkbox.isSelected()) { | ||
checkbox.click(); | ||
} | ||
} | ||
|
||
DemoPageData dpd = openDemoTabs(false); | ||
openPopupWindow(dpd); | ||
for (WebElement button : popupPage.allExportTabsCustomFormatButtons) { | ||
Assert.assertTrue(button.isDisplayed()); | ||
} | ||
} | ||
|
||
@Test | ||
public void showCustomFormatOfCurrentTab() { | ||
openSingleLinkOptionsPage(); | ||
SingleLinkOptionsPage page = new SingleLinkOptionsPage(driver); | ||
for (WebElement checkbox : page.allCustomFormatCheckboxes) { | ||
if (!checkbox.isSelected()) { | ||
checkbox.click(); | ||
} | ||
} | ||
|
||
DemoPageData dpd = openDemoTabs(false); | ||
openPopupWindow(dpd); | ||
for (WebElement button : popupPage.allExportCurrentTabCustomFormatButtons) { | ||
Assert.assertTrue(button.isDisplayed()); | ||
} | ||
} | ||
} |
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
38 changes: 0 additions & 38 deletions
38
e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/popup/SimpleTest.java
This file was deleted.
Oops, something went wrong.
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