硒IDE

2013-03-28 84 views
0

以下处理JavaScript是我失败的提交按钮后的点击例子:硒IDE

package demo; 

import static org.junit.Assert.assertEquals; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.server.SeleniumServer; 

import com.thoughtworks.selenium.DefaultSelenium; 
import com.thoughtworks.selenium.Selenium; 

public class leadtest 
     { 
    private Selenium selenium; 
    private SeleniumServer server; 

    @Before 
    public void setUp() throws Exception 
       { 
     server = new SeleniumServer(); 
     server.start(); 
     selenium = new DefaultSelenium("localhost", 4444, "*firefox", 
      "http://www.careerfundas.com/"); 
     selenium.start(); 
      } 

    @Test 
    public void testLeadtest() throws Exception 
       { 
     selenium.open("/"); 
     selenium.click("id=wrapper"); 
     selenium.click("css=a.active-home > span"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("id=wrapper"); 
     selenium.click("css=li"); 
     selenium.waitForPageToLoad("30000"); 
     selenium.click("id=confused_name"); 
     selenium.type("id=confused_name", "Shalini test"); 
     selenium.type("id=confused_email", "[email protected]"); 
     selenium.type("id=confused_phoneno", "9090909090"); 
     selenium.select("id=conf_course", "label=Shipping and Logistics"); 
     selenium.click("link=Ask Expert"); 
     assertEquals(
      "Thank You ! Someone from Career Fundas experts panel will contact you shortly.", selenium.getAlert()); 


      } 



    @After 
    public void tearDown() throws Exception 
     { 
     selenium.stop(); 
    } 

     } 

注: 下面是当我试图上述Java脚本运行我正在错误。

com.thoughtworks.selenium.SeleniumException: ERROR: There were no alerts 
at com.thoughtworks.selenium.HttpCommandProcessor. 
throwAssertionFailureExceptionOrError (HttpCommandProcessor.java:112) 
+0

可能是工作,不是由时间服务器正在执行'getAlert()'命令显示的警报。尝试在声明语句之前添加'selenium.waitforpagetoload(30000);' 并检查行为。如果你仍然面临问题。让我们知道。 – Hemanth 2013-03-28 05:35:24

回答

0
  1. 您可以尝试设置速度selenium.setSpeed("5000")你 做geralert之前。

  2. 也许这不是预警。也许这是确认。 你尝试selenium.getConfirmation();

Here是一些关于它的更多信息。

0
selenium.click("link=Ask Expert"); 
Thread.sleep(5000); 
assertEquals("Thank You ! Someone from Career Fundas experts panel will contact you shortly.", selenium.getAlert()); 

使用此代码,它在我结束