2016-04-13 12:17:46 +00:00
|
|
|
package sharelatex
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/tebeka/selenium"
|
|
|
|
)
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
type driver struct {
|
|
|
|
wd selenium.WebDriver
|
|
|
|
retries uint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d driver) FindXpath(selector string) selenium.WebElement {
|
|
|
|
return d.Find(selenium.ByXPATH, selector)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d driver) FindByCSS(selector string) selenium.WebElement {
|
|
|
|
return d.Find(selenium.ByCSSSelector, selector)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d driver) FindByName(selector string) selenium.WebElement {
|
|
|
|
return d.Find(selenium.ByName, selector)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d driver) FindByText(selector string) selenium.WebElement {
|
|
|
|
return d.Find(selenium.ByLinkText, selector)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d driver) Find(by, selector string) selenium.WebElement {
|
|
|
|
for i := uint(0); i < d.retries; i++ {
|
|
|
|
e, err := d.wd.FindElement(by, selector)
|
|
|
|
if err == nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "elemenet %s not found (%s)", selector, by)
|
|
|
|
os.Exit(1)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-13 12:17:46 +00:00
|
|
|
func IntegrationTest(url string) error {
|
|
|
|
_, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("failed to get '%s': %s", url, err)
|
|
|
|
}
|
|
|
|
caps := selenium.Capabilities{"browserName": "firefox"}
|
|
|
|
wd, err := selenium.NewRemote(caps, "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer wd.Quit()
|
2016-05-09 15:33:33 +00:00
|
|
|
d := driver{wd, 100}
|
2016-04-13 12:17:46 +00:00
|
|
|
|
|
|
|
// Get simple playground interface
|
2016-05-09 15:33:33 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "visit url %s\n", url)
|
2016-04-13 12:17:46 +00:00
|
|
|
wd.Get(url)
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e := d.FindXpath("//input[@type='email']")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Clear()
|
|
|
|
e.SendKeys("joerg@higgsboson.tk")
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindXpath("//input[@type='password']")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Clear()
|
|
|
|
e.SendKeys("password")
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindXpath("//button[@type='submit']")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
d.FindByText("Account")
|
2016-04-13 12:17:46 +00:00
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByText("New Project")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByText("Blank Project")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindXpath("//input[@type='text']")
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Clear()
|
|
|
|
e.SendKeys(fmt.Sprintf("p %d", rand.Int63()))
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByCSS("button.btn-primary") // Create
|
|
|
|
e.Click()
|
|
|
|
|
|
|
|
e = d.FindXpath("//a[@ng-controller='ShareController']") // Share
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByCSS("button.btn-primary") // Close
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByCSS(`i.fa-comment`)
|
|
|
|
e.Click()
|
|
|
|
|
|
|
|
e = d.FindByCSS(`div.new-message textarea`)
|
2016-04-13 12:17:46 +00:00
|
|
|
e.SendKeys("hello world" + selenium.EnterKey)
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByCSS("i.fa.fa-upload") // Upload
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Click()
|
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByName("file") // Create
|
2016-04-13 12:17:46 +00:00
|
|
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
2016-06-15 10:38:08 +00:00
|
|
|
e.SendKeys(filepath.Join(dir, "./tech-support.jpg"))
|
2016-04-13 12:17:46 +00:00
|
|
|
|
2016-05-09 15:33:33 +00:00
|
|
|
e = d.FindByCSS("textarea") // Latex Doc
|
2016-04-13 12:17:46 +00:00
|
|
|
e.Clear()
|
|
|
|
e.SendKeys(`\documentclass{article} \begin{document} ello \end{document}`)
|
2016-05-09 15:33:33 +00:00
|
|
|
|
2016-04-13 12:17:46 +00:00
|
|
|
time.Sleep(time.Millisecond * 1000)
|
|
|
|
return nil
|
|
|
|
}
|