2014-03-12 2 views
2

편집 : 이것은 Windows의 동작으로, Linux에서만 작동합니다.CasperJS- 사이트에 등록하고 Gmail에서 보낸 메일의 유효성을 검사합니다 .- 슬림하고 유령 모두 -

첫 번째로 캐스퍼를 사용하여 Gmail을 탐색하는 데 성공하면 (임의 대기 시간 - 20 초에서 5 분 -), 알려주세요.

Google 사이트에 등록하고 Gmail (전체 등록 단계)을 통해 자동으로 내 등록을 확인하고 싶습니다. 누군가 이전에 그렇게 했습니까?

등록 할 때 아무런 문제가 없으며 내 사서함 (Gmail)에 로그인 할 수 있지만 Gmail에서 내 등록을 확인하고 확인하는 데 문제가 있으며 phantomJS와 slimerJS간에 서로 다른 동작을 관찰합니다.

팬텀에서는 특수 명령없이 작동하지만 다음 단계 (waitForSelector)에서 통과하기까지 5 분 정도 걸릴 수 있습니다. 그리고 slimerjs로 그냥 사서함 페이지에 붙어있어.

EDIT : 이상한 점 : 팝업이 열리는 링크를 수동으로 (슬리머로) 클릭하면 차단되는 것을 멈추고 내비게이션이 계속 진행되며 단계 자체의 끝을 감지 할 수없는 것과 같습니다. 다른 상호 작용없이 제출 클릭 후 waitFor를 수행하십시오. 새로 고침/다시로드 문제입니까?

것은 그 자신을 확인하십시오 :

casper.thenOpen('https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en', function(){ 
    this.sendKeys("input#Email","your mail"); 
    this.sendKeys("input#Passwd","your password"); 
    this.click("input#signIn.rc-button-submit"); 
    console.log(this.getCurrentUrl()); 
    this.waitForSelector(".aeF",function(){//fail with linux -> timeout 
     this.test.pass("ok"); //windows -> stuck in slimer, several times in phantom 
     this.test.assertExists(".T-I.J-J5-Ji.T-I-KE.L3","Gmail Home ok"); 
     console.log("url "+this.getCurrentUrl()); 
    }); 

그리고 난 모든 시간 초과 오류가 발생하지 않습니다. slimerjs에서는 그냥 페이지를 열어 두었습니다.

waitForUrl 대신 waitForPopup을 수행하면 오류 (시간 초과 -> 팝업되지 않음)가 표시되는데 왜 waitForUrl/waitForSelector ...가 멈추지 않습니까? 나는 시도했다 - 웹 보안 = 아니요, - ignore-ssl-errors = true 명령 (링크되지 않았지만 시도했는데 --output-encoding = ISO 8859-1도 작동하지 않음). 여기

팬텀과 slimer (문서)의 차이 : 문제가 아약스에 기본 Gmail은 루프입니다 : 는

답변

2

음 (내가 생각하는이 문제에 쓸모없는) , 우리는 마침내 그것을 할 수있는 방법을 발견 http://docs.slimerjs.org/0.8/differences-with-phantomjs.html을 요청, 일부 새 메일 확인 등 ... Page polls remote url을 참조하십시오. casper가 단계적으로 차단하게됩니다. casperJs+gmail

스크립트가 정상적으로 작동 방법 :

다행히도 구글은 단순화 된 HTML 버전을 사용하는 것을 방지 할 수있는 방법을 제안한다 (당신은 예를 들어,이 버전을 사용하여 테스트를위한 특별한 Gmail 주소를 사용할 수 있습니다) .

보너스 :

/* 
* Click on an element specified by its selector and a part of its text content. 
* This method resolves some problem as random space in textNode/more flexible too. 
* Need to fix one bug though : when there is a tag in textContent of our selector. 
*/ 
casper.clickSelectorHasText = function (selector, containsText){ 
    var tmp = this.getElementsInfo(selector) 
     ,i 
     ,l 
     ,bool=false 
     ; 
    for (i=0,l=tmp.length;i<l; i++){ 
     if(tmp[i].text && tmp[i].text.indexOf(containsText)!==-1){ 
      this.clickLabel(tmp[i].text); 
      bool=true; 
      break; 
     } 
    } 
    casper.test.assert(bool, "clickSelectorHasText done, text and selector found -> click selector " + selector +" which contains text " + containsText); 
}; 

casper.thenOpen('https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en', function scrapeCode(){ 
     //log in 
     this.sendKeys("input#Email","your email"); 
     this.sendKeys("input#Passwd","your password"); 
     this.click("input#signIn.rc-button-submit"); 
     //wait to redirect to our mailbox 
     this.waitForSelector("form[name='f']",function(){ 
      //check main block 
      this.test.assertExists("form[name='f']","Gmail Home ok"); 
      this.test.assertSelectorHasText("span", "Your gmail title message"); 
      this.clickSelectorHasText("font", "one string which appears in font tag"); 
      //wait inscription message appears 
      this.waitForSelector("div.msg",function(){ 
       this.test.assertSelectorHasText("a","the message which activates your account--> in <a>"); 
      }); 
     }) 
     //validate our account 
     .then(function(){ 
      this.clickLabel("the message which activates your account--> in <a>"); 
      this.waitForPopup(/mail/, function(){ 
       this.test.pass("popup opened"); 
      }); 
      this.withPopup(/mail/, function(){ 
       this.viewport(1400,800); 
       this.test.pass("With Popup"); 
       //wait something on your website (for me selector .boxValid) 
       this.waitForSelector(".boxValid", function(){ 
        /* 
        * Here your code after validation 
        */ 
       }); 

      }); 
     }) 

이 정상 Gmail을 사용하여 이벤트와 함께 할 을 resource.received보고 할 수 있습니다.