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

Feature/#220 iframe support #315

Merged
merged 25 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cover:
curl -s https://codecov.io/bash | bash

e2e:
go run ${DIR_E2E}/main.go --tests ${DIR_E2E}/tests --pages ${DIR_E2E}/pages --filter doc_cookie_set*
go run ${DIR_E2E}/main.go --tests ${DIR_E2E}/tests --pages ${DIR_E2E}/pages

bench:
go test -run=XXX -bench=. ${DIR_PKG}/...
Expand Down
34 changes: 31 additions & 3 deletions e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/MontFerret/ferret/e2e/runner"
"github.com/MontFerret/ferret/e2e/server"
"github.com/rs/zerolog"
"net"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -39,6 +40,20 @@ var (
)
)

func getOutboundIP() (net.IP, error) {
conn, err := net.Dial("udp", "8.8.8.8:80")

if err != nil {
return nil, err
}

defer conn.Close()

localAddr := conn.LocalAddr().(*net.UDPAddr)

return localAddr.IP, nil
}

func main() {
flag.Parse()

Expand Down Expand Up @@ -91,9 +106,22 @@ func main() {
}
}

var ipAddr string

// we need it in those cases when a Chrome instance is running inside a container
// and it needs an external IP to get access to our static web server
outIP, err := getOutboundIP()

if err != nil {
ipAddr = "0.0.0.0"
logger.Warn().Err(err).Msg("Failed to get outbound IP address")
} else {
ipAddr = outIP.String()
}

r := runner.New(logger, runner.Settings{
StaticServerAddress: fmt.Sprintf("http://0.0.0.0:%d", staticPort),
DynamicServerAddress: fmt.Sprintf("http://0.0.0.0:%d", dynamicPort),
StaticServerAddress: fmt.Sprintf("http://%s:%d", ipAddr, staticPort),
DynamicServerAddress: fmt.Sprintf("http://%s:%d", ipAddr, dynamicPort),
CDPAddress: *cdp,
Dir: *testsDir,
Filter: filterR,
Expand All @@ -110,7 +138,7 @@ func main() {
}
}()

err := r.Run(ctx)
err = r.Run(ctx)

if err != nil {
os.Exit(1)
Expand Down
33 changes: 19 additions & 14 deletions e2e/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,27 @@ func (r *Runner) runQueries(ctx context.Context, dir string) ([]Result, error) {

r.logger.Info().Timestamp().Str("name", fName).Msg("Running test")

result := r.runQuery(ctx, c, fName, string(b))
select {
case <-ctx.Done():
return nil, context.Canceled
default:
result := r.runQuery(ctx, c, fName, string(b))

if result.err == nil {
r.logger.Info().
Timestamp().
Str("file", result.name).
Msg("Test passed")
} else {
r.logger.Error().
Timestamp().
Err(result.err).
Str("file", result.name).
Msg("Test failed")
}

if result.err == nil {
r.logger.Info().
Timestamp().
Str("file", result.name).
Msg("Test passed")
} else {
r.logger.Error().
Timestamp().
Err(result.err).
Str("file", result.name).
Msg("Test failed")
results = append(results, result)
}

results = append(results, result)
}

return results, nil
Expand Down
11 changes: 4 additions & 7 deletions e2e/tests/el_value_d.fql
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
LET url = @static + '/value.html'
LET url = @dynamic + "?redirect=/forms"
LET doc = DOCUMENT(url, true)

LET expected = ["068728","068728","816410","52024413","698690","210583","049700","826394","354369","135911","700285","557242","278832","357701","313034","959368","703500","842750","777175","378061","072489","383005","843393","59912263","464535","229710","230550","767964","758862","944384","025449","010245","844935","038760","013450","124139","211145","758761","448667","488966"]
LET el = ELEMENT(doc, "#select_input")

LET actual = (
FOR tr IN ELEMENTS(doc, '#listings_table > tbody > tr')
LET elem = ELEMENT(tr, 'td > input')
RETURN elem.value
)
LET expected = "1"
LET actual = el.value

RETURN EXPECT(actual, expected)
5 changes: 4 additions & 1 deletion e2e/tests/page_load_d.fql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
LET url = @dynamic
LET doc = DOCUMENT(url, true)

RETURN EXPECT(doc.url, url)
LET expected = url + '/'
LET actual = doc.url

RETURN EXPECT(expected, actual)
5 changes: 5 additions & 0 deletions examples/iframes.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LET page = DOCUMENT("https://www.w3schools.com/html/html_iframe.asp", { driver: "cdp" })

LET c2 = page.frames[1].head.innerHTML

RETURN c2
11 changes: 7 additions & 4 deletions examples/pagination.fql
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ INPUT(amazon, '#twotabsearchtextbox', @criteria)
CLICK(amazon, '.nav-search-submit input[type="submit"]')
WAIT_NAVIGATION(amazon)

LET resultListSelector = '#s-results-list-atf'
LET resultItemSelector = '.s-result-item.celwidget'
LET nextBtnSelector = '#pagnNextLink'
LET resultListSelector = 'div.s-result-list'
LET resultItemSelector = 'div.s-result-item'
LET nextBtnSelector = 'ul.a-pagination .a-last a'
LET vendorSelector1 = 'div > div:nth-child(3) > div:nth-child(2) > span:nth-child(2)'
LET vendorSelector2 = 'div > div:nth-child(5) > div:nth-child(2) > span:nth-child(2)'
LET priceWholeSelector = 'span.sx-price-whole'
LET priceFracSelector = 'sup.sx-price-fractional'
LET pages = TO_INT(INNER_TEXT(amazon, '#pagn > span.pagnDisabled'))
LET pagers = ELEMENTS(amazon, 'ul.a-pagination li.a-disabled')
LET pages = LENGTH(pagers) > 0 ? TO_INT(INNER_TEXT(LAST(pagers))) : 0

LET result = (
FOR pageNum IN 1..pages
LET clicked = pageNum == 1 ? false : CLICK(amazon, nextBtnSelector)
LET wait = clicked ? WAIT_NAVIGATION(amazon) : false
LET waitSelector = wait ? WAIT_ELEMENT(amazon, resultListSelector) : false

PRINT("page:", pageNum, "clicked", clicked)

LET items = (
FOR el IN ELEMENTS(amazon, resultItemSelector)
LET priceWholeTxt = INNER_TEXT(el, priceWholeSelector)
Expand Down
3 changes: 3 additions & 0 deletions examples/screenshot.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LET data = SCREENSHOT("https://github.com/MontFerret/ferret/raw/master/assets/logo.png")

RETURN { type: "png", data }
4 changes: 2 additions & 2 deletions pkg/compiler/compiler_str_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RETURN %s<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>GetTitle</title>
</head>
<body>
Hello world
Expand All @@ -43,7 +43,7 @@ RETURN %s<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>GetTitle</title>
</head>
<body>
Hello world
Expand Down
Loading