Skip to content

Commit

Permalink
improve browser filter
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Dec 1, 2023
1 parent b1baa88 commit 2d9610d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
4 changes: 4 additions & 0 deletions scripts/browserstack/browsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (x *Client) ReducedBrowsers(ctx context.Context) ([]Browser, error) {
continue // android can't be tested with Browserstack
}

if strings.Contains(strings.ToLower(b.Browser), "opera") {
continue // seems to be broken in browserstack
}

if b.Browser == "edge" {
parts := strings.Split(b.BrowserVersion, ".")
if len(parts) > 0 {
Expand Down
6 changes: 6 additions & 0 deletions scripts/store/select_browsers_by_search.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT browser_version, browser, os_version, os
FROM user_agents
WHERE (browser = ? OR os = ?) AND browserstack = 1
GROUP BY browser, browser_version, os, os_version
ORDER BY RANDOM()
LIMIT 50
66 changes: 66 additions & 0 deletions scripts/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,72 @@ UA_LOOP:
return out, nil
}

//go:embed select_browsers_by_search.sql
var selectBrowsersBySearchQuery string

func SelectBrowsersBySearch(ctx context.Context, db *sql.DB, allBrowsers []browserstack.Browser, search string) ([]browserstack.Browser, error) {
rows, err := db.QueryContext(
ctx,
selectBrowsersBySearchQuery,
search,
search,
)
if err == sql.ErrNoRows {
return allBrowsers, nil
}
if err != nil {
return nil, err
}

uas := []browserua.UserAgent{}
for rows.Next() {
ua := browserua.UserAgent{}
err = rows.Scan(&ua.BrowserVersion, &ua.Browser, &ua.OSVersion, &ua.OS)
if err != nil {
log.Printf("Error %s when scanning all user agents by priority", err)
return nil, err
}

uas = append(uas, ua)
}

if rows.Err() != nil {
log.Printf("Error %s when scanning all user agents by priority", err)
return nil, err
}

rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(uas), func(i, j int) {
uas[i], uas[j] = uas[j], uas[i]
})

out := []browserstack.Browser{}

UA_LOOP:
for _, ua := range uas {
ua := ua
for _, browser := range allBrowsers {
if ua.OS == browser.OS && ua.OS != "" && ua.OSVersion != "" && ua.OS == "ios" {
if strings.Split(ua.OSVersion, ".")[0] == strings.Split(browser.OSVersion, ".")[0] {
browser.RealBrowser = &ua
out = append(out, browser)
continue UA_LOOP
}
}

if ua.Browser == browser.Browser && ua.Browser != "" && ua.BrowserVersion != "" && ua.OS != "ios" && browser.OS != "ios" {
if strings.Split(ua.BrowserVersion, ".")[0] == strings.Split(browser.BrowserVersion, ".")[0] {
browser.RealBrowser = &ua
out = append(out, browser)
continue UA_LOOP
}
}
}
}

return out, nil
}

//go:embed select_results_for_ua_and_polyfill_list.sql
var selectResultsForUAAndPolyfillListQuery string

Expand Down
24 changes: 10 additions & 14 deletions scripts/web-tests-browserstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,17 @@ func run(processCtx context.Context, runnerCtx context.Context, db *sql.DB, chun
return
}

browsers, err := store.SelectBrowsersByPriority(ctx, db, allBrowsers)
if err != nil {
panic(err)
}
var browsers []browserstack.Browser

if browserFilter != "" {
filteredBrowsers := []browserstack.Browser{}
for _, b := range browsers {
if strings.Contains(strings.ToLower(b.ResultKey()), strings.ToLower(browserFilter)) {
filteredBrowsers = append(filteredBrowsers, b)
}
if browserFilter == "" {
browsers, err = store.SelectBrowsersByPriority(ctx, db, allBrowsers)
if err != nil {
panic(err)
}

if len(filteredBrowsers) > 0 {
browsers = filteredBrowsers
} else {
browsers, err = store.SelectBrowsersBySearch(ctx, db, allBrowsers, browserFilter)
if err != nil {
panic(err)
}
}

Expand Down Expand Up @@ -287,7 +283,7 @@ func runTest(parentCtx context.Context, db *sql.DB, client *browserstack.Client,
w3cCompatible = true
}
} else if browser.Browser == "safari" {
if browserVersion != nil && browserVersion.Segments()[0] > 11 {
if browserVersion != nil && browserVersion.Segments()[0] > 10 {
w3cCompatible = true
}
} else if browser.Browser == "edge" {
Expand Down
Binary file modified web-tests.db
Binary file not shown.

0 comments on commit 2d9610d

Please sign in to comment.