简体   繁体   中英

Selenium tests not getting executed on Eclipse

I am trying to login to our company product site via selenium.I am able to do it via the Selenium IDE. And this is the code that the IDE exports using JUnit4(Remote Control):

package com.beginning;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class testcase extends SeleneseTestCase {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "link");
        selenium.start();
    }

    @Test
    public void testTestcase() throws Exception {
        selenium.open("complete link");
        selenium.type("name=j_username", "username");
        selenium.type("name=j_password", "password");
        selenium.click("css=input[type=\"submit\"]");
        selenium.waitForPageToLoad("30000");
        //selenium.click("link=Sign out");
        //selenium.waitForPageToLoad("30000");
    }

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

My doubts are :

1.Why does selenium IDE export the browser type as *chrome when I am actually doing it in firefox. 2.If I use the test as it is, it enters the values and then gives an exception . 3.If I change the browser Type to *firefox, it starts execution but nothing happens at all. Basically hangs.

Things work fine when doing it from the IDE.

Thanks.

Would reccommend you to check the version of firefox and upgrade to latest.I have used a similar scenario. Pls find the code below. You can use this its works grt.Hope you find it useful.

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


public class TestRun {
public static void main(String[] args)
{
Selenium selenium=new DefaultSelenium("localhost", 4444 , "*firefox","myurl");
selenium.start();
selenium.open("myurl");
System.out.println("Open browser "+selenium);
selenium.windowMaximize();
selenium.type("id=j_username","Lal");
selenium.type("name=j_password","lal");
selenium.click("name=submit");
**selenium.waitForPageToLoad("60000");**
if(selenium.isTextPresent("Lal"))
{
    selenium.click("id=common_header_logout");
}
else
{
    System.out.println("User not found");
}
}
}

更改您的"link"DefaultSelenium构造函数的第四个参数),使其实际上是一个有效的URL(您要定位的网站)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM