Skip to content

Commit

Permalink
Test single page export, and popup visibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkxin committed Aug 30, 2024
1 parent 1cc3a54 commit e01f93b
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ protected void openCustomFormatPage(String context, String slot) {
driver.get(getExtensionProtocol()+"://"+extId+"/dist/ui/custom-format.html?context="+context+"&slot="+slot);
}

protected void openMultipleLinksOptionsPage() {
driver.get(getExtensionProtocol()+"://"+extId+"/dist/ui/multiple-links.html");
}

protected void openSingleLinkOptionsPage() {
driver.get(getExtensionProtocol()+"://"+extId+"/dist/ui/single-link.html");
}

protected String getExtensionProtocol() {
return switch (browser) {
case BROWSER_CHROME -> "chrome-extension";
Expand Down
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);
}
}
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);
}
}
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);
}
}
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public class PopupPage {
@FindBy(css = "button[value='export-tabs'][data-scope='highlighted'][data-format='custom-format'][data-custom-format-slot='2']")
public WebElement highlightedTabsCustomFormat2;

@FindBy(css = "button[value='export-current-tab'][data-format='custom-format'][data-custom-format-slot='1']")
public WebElement currentTabCustomFormat1;

@FindBy(css="button[value='export-tabs'][data-format='custom-format']")
public List<WebElement> allExportTabsCustomFormatButtons;

@FindBy(css="button[value='export-current-tabs'][data-format='custom-format']")
public List<WebElement> allExportCurrentTabCustomFormatButtons;

public PopupPage(WebDriver driver) {
PageFactory.initElements(driver, this);
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/testng-chrome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.tabs.TabExportingTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.tabs.TabExportingWithGroupsTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.tabs.NoPermissionTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.SimpleTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.DisplayTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.TabExportingTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.TabExportingWithGroupsTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.NoPermissionTest"/>
Expand Down
2 changes: 1 addition & 1 deletion e2e/testng-firefox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.OnPageContentsTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.tabs.TabExportingTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.keyboardshortcut.tabs.NoPermissionTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.SimpleTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.DisplayTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.TabExportingTest"/>
<class name="org.yorkxin.copyasmarkdown.e2e.popup.NoPermissionTest"/>
</classes>
Expand Down

0 comments on commit e01f93b

Please sign in to comment.