Yes, just like a fish. The strange thing is that they were not fish at
all: they were reptiles like lizards, snakes, and crocodiles. You can
easily tell this by looking at the skull and fins.
A similar case is known for mammals too: think about dolphins and whales.
Ichthyosaurs swam in the Mesozoic ocean when dinosaurs walked on land. To
be precise, they appeared slightly earlier than dinosaurs (250 million
years ago versus 230 ma) and disappeared again earlier (90 ma versus 65
ma).
The earliest ichthyosaurs are known from the Lower Triassic strata of
Canada, China, Japan, Spitsbergen, and possibly Thailand. These first
ichthyosaurs were not yet very much fish-shaped. Rather, they looked like
a lizard with fins, just like in the figure below (fins were added from
other specimens).
Ichthyosaurs diversified very quickly once they appeared. Several
different body plans emerged in the Early and Middle Triassic. But, if you
simplify the matter, you can see that there was a general transition from
lizard-shaped body plan to fish-shaped one through the evolution of
ichthyosaurs, as in the figure below.